Project: Identify Customer Segments¶

In this project, you will apply unsupervised learning techniques to identify segments of the population that form the core customer base for a mail-order sales company in Germany. These segments can then be used to direct marketing campaigns towards audiences that will have the highest expected rate of returns. The data that you will use has been provided by our partners at Bertelsmann Arvato Analytics, and represents a real-life data science task.

This notebook will help you complete this task by providing a framework within which you will perform your analysis steps. In each step of the project, you will see some text describing the subtask that you will perform, followed by one or more code cells for you to complete your work. Feel free to add additional code and markdown cells as you go along so that you can explore everything in precise chunks. The code cells provided in the base template will outline only the major tasks, and will usually not be enough to cover all of the minor tasks that comprise it.

It should be noted that while there will be precise guidelines on how you should handle certain tasks in the project, there will also be places where an exact specification is not provided. There will be times in the project where you will need to make and justify your own decisions on how to treat the data. These are places where there may not be only one way to handle the data. In real-life tasks, there may be many valid ways to approach an analysis task. One of the most important things you can do is clearly document your approach so that other scientists can understand the decisions you've made.

At the end of most sections, there will be a Markdown cell labeled Discussion. In these cells, you will report your findings for the completed section, as well as document the decisions that you made in your approach to each subtask. Your project will be evaluated not just on the code used to complete the tasks outlined, but also your communication about your observations and conclusions at each stage.

In [ ]:
# import libraries here; add more as necessary
import warnings
import plotly.express as px
import plotly
plotly.offline.init_notebook_mode()
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import joblib
import sklearn
from sklearn.preprocessing import OneHotEncoder ,StandardScaler
from sklearn.impute import SimpleImputer
 
# magic word for producing visualizations in notebook
%matplotlib inline

pd.options.display.max_rows = None
pd.options.display.max_columns = None

Step 0: Load the Data¶

There are four files associated with this project (not including this one):

  • Udacity_AZDIAS_Subset.csv: Demographics data for the general population of Germany; 891211 persons (rows) x 85 features (columns).
  • Udacity_CUSTOMERS_Subset.csv: Demographics data for customers of a mail-order company; 191652 persons (rows) x 85 features (columns).
  • Data_Dictionary.md: Detailed information file about the features in the provided datasets.
  • AZDIAS_Feature_Summary.csv: Summary of feature attributes for demographics data; 85 features (rows) x 4 columns

Each row of the demographics files represents a single person, but also includes information outside of individuals, including information about their household, building, and neighborhood. You will use this information to cluster the general population into groups with similar demographic properties. Then, you will see how the people in the customers dataset fit into those created clusters. The hope here is that certain clusters are over-represented in the customers data, as compared to the general population; those over-represented clusters will be assumed to be part of the core userbase. This information can then be used for further applications, such as targeting for a marketing campaign.

To start off with, load in the demographics data for the general population into a pandas DataFrame, and do the same for the feature attributes summary. Note for all of the .csv data files in this project: they're semicolon (;) delimited, so you'll need an additional argument in your read_csv() call to read in the data properly. Also, considering the size of the main dataset, it may take some time for it to load completely.

Once the dataset is loaded, it's recommended that you take a little bit of time just browsing the general structure of the dataset and feature summary file. You'll be getting deep into the innards of the cleaning in the first major step of the project, so gaining some general familiarity can help you get your bearings.

In [ ]:
# Load in the general demographics data.
demographicData=pd.read_csv('Udacity_AZDIAS_Subset.csv',sep=';', on_bad_lines='warn')
FeatureSummary=pd.read_csv('AZDIAS_Feature_Summary.csv',sep=';', on_bad_lines='warn')

'GEBAEUDETYP_5.0' in FeatureSummary['attribute']
Out[ ]:
False
In [ ]:
print('number of rows :' , demographicData.shape[0])
print('number of columns :' , demographicData.shape[1])
display(demographicData.head(5))
number of rows : 891221
number of columns : 85
AGER_TYP ALTERSKATEGORIE_GROB ANREDE_KZ CJT_GESAMTTYP FINANZ_MINIMALIST FINANZ_SPARER FINANZ_VORSORGER FINANZ_ANLEGER FINANZ_UNAUFFAELLIGER FINANZ_HAUSBAUER FINANZTYP GEBURTSJAHR GFK_URLAUBERTYP GREEN_AVANTGARDE HEALTH_TYP LP_LEBENSPHASE_FEIN LP_LEBENSPHASE_GROB LP_FAMILIE_FEIN LP_FAMILIE_GROB LP_STATUS_FEIN LP_STATUS_GROB NATIONALITAET_KZ PRAEGENDE_JUGENDJAHRE RETOURTYP_BK_S SEMIO_SOZ SEMIO_FAM SEMIO_REL SEMIO_MAT SEMIO_VERT SEMIO_LUST SEMIO_ERL SEMIO_KULT SEMIO_RAT SEMIO_KRIT SEMIO_DOM SEMIO_KAEM SEMIO_PFLICHT SEMIO_TRADV SHOPPER_TYP SOHO_KZ TITEL_KZ VERS_TYP ZABEOTYP ALTER_HH ANZ_PERSONEN ANZ_TITEL HH_EINKOMMEN_SCORE KK_KUNDENTYP W_KEIT_KIND_HH WOHNDAUER_2008 ANZ_HAUSHALTE_AKTIV ANZ_HH_TITEL GEBAEUDETYP KONSUMNAEHE MIN_GEBAEUDEJAHR OST_WEST_KZ WOHNLAGE CAMEO_DEUG_2015 CAMEO_DEU_2015 CAMEO_INTL_2015 KBA05_ANTG1 KBA05_ANTG2 KBA05_ANTG3 KBA05_ANTG4 KBA05_BAUMAX KBA05_GBZ BALLRAUM EWDICHTE INNENSTADT GEBAEUDETYP_RASTER KKK MOBI_REGIO ONLINE_AFFINITAET REGIOTYP KBA13_ANZAHL_PKW PLZ8_ANTG1 PLZ8_ANTG2 PLZ8_ANTG3 PLZ8_ANTG4 PLZ8_BAUMAX PLZ8_HHZ PLZ8_GBZ ARBEIT ORTSGR_KLS9 RELAT_AB
0 -1 2 1 2.0 3 4 3 5 5 3 4 0 10.0 0 -1 15.0 4.0 2.0 2.0 1.0 1.0 0 0 5.0 2 6 7 5 1 5 3 3 4 7 6 6 5 3 -1 NaN NaN -1 3 NaN NaN NaN 2.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 1.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 -1 1 2 5.0 1 5 2 5 4 5 1 1996 10.0 0 3 21.0 6.0 5.0 3.0 2.0 1.0 1 14 1.0 5 4 4 3 1 2 2 3 6 4 7 4 7 6 3 1.0 0.0 2 5 0.0 2.0 0.0 6.0 NaN 3.0 9.0 11.0 0.0 8.0 1.0 1992.0 W 4.0 8 8A 51 0.0 0.0 0.0 2.0 5.0 1.0 6.0 3.0 8.0 3.0 2.0 1.0 3.0 3.0 963.0 2.0 3.0 2.0 1.0 1.0 5.0 4.0 3.0 5.0 4.0
2 -1 3 2 3.0 1 4 1 2 3 5 1 1979 10.0 1 3 3.0 1.0 1.0 1.0 3.0 2.0 1 15 3.0 4 1 3 3 4 4 6 3 4 7 7 7 3 3 2 0.0 0.0 1 5 17.0 1.0 0.0 4.0 NaN 3.0 9.0 10.0 0.0 1.0 5.0 1992.0 W 2.0 4 4C 24 1.0 3.0 1.0 0.0 0.0 3.0 2.0 4.0 4.0 4.0 2.0 3.0 2.0 2.0 712.0 3.0 3.0 1.0 0.0 1.0 4.0 4.0 3.0 5.0 2.0
3 2 4 2 2.0 4 2 5 2 1 2 6 1957 1.0 0 2 0.0 0.0 0.0 0.0 9.0 4.0 1 8 2.0 5 1 2 1 4 4 7 4 3 4 4 5 4 4 1 0.0 0.0 1 3 13.0 0.0 0.0 1.0 NaN NaN 9.0 1.0 0.0 1.0 4.0 1997.0 W 7.0 2 2A 12 4.0 1.0 0.0 0.0 1.0 4.0 4.0 2.0 6.0 4.0 0.0 4.0 1.0 0.0 596.0 2.0 2.0 2.0 0.0 1.0 3.0 4.0 2.0 3.0 3.0
4 -1 3 1 5.0 4 3 4 1 3 2 5 1963 5.0 0 3 32.0 10.0 10.0 5.0 3.0 2.0 1 8 5.0 6 4 4 2 7 4 4 6 2 3 2 2 4 2 2 0.0 0.0 2 4 20.0 4.0 0.0 5.0 1.0 2.0 9.0 3.0 0.0 1.0 4.0 1992.0 W 3.0 6 6B 43 1.0 4.0 1.0 0.0 0.0 3.0 2.0 5.0 1.0 5.0 3.0 3.0 5.0 5.0 435.0 2.0 4.0 2.0 1.0 2.0 3.0 3.0 4.0 6.0 5.0
In [ ]:
# Check the structure of the data after it's loaded (e.g. print the number of
# rows and columns, print the first few rows).

print('number of rows :' , FeatureSummary.shape[0])
print('number of columns :' , FeatureSummary.shape[1])
display(FeatureSummary.loc[FeatureSummary['attribute']=='PRAEGENDE_JUGENDJAHRE'].head(4))
number of rows : 85
number of columns : 4
attribute information_level type missing_or_unknown
22 PRAEGENDE_JUGENDJAHRE person mixed [-1,0]
In [ ]:
FeatureSummary['type'].unique()

 
Out[ ]:
array(['categorical', 'ordinal', 'numeric', 'mixed', 'interval'],
      dtype=object)

Tip: Add additional cells to keep everything in reasonably-sized chunks! Keyboard shortcut esc --> a (press escape to enter command mode, then press the 'A' key) adds a new cell before the active cell, and esc --> b adds a new cell after the active cell. If you need to convert an active cell to a markdown cell, use esc --> m and to convert to a code cell, use esc --> y.

Step 1: Preprocessing¶

Step 1.1: Assess Missing Data¶

The feature summary file contains a summary of properties for each demographics data column. You will use this file to help you make cleaning decisions during this stage of the project. First of all, you should assess the demographics data in terms of missing data. Pay attention to the following points as you perform your analysis, and take notes on what you observe. Make sure that you fill in the Discussion cell with your findings and decisions at the end of each step that has one!

Step 1.1.1: Convert Missing Value Codes to NaNs¶

The fourth column of the feature attributes summary (loaded in above as feat_info) documents the codes from the data dictionary that indicate missing or unknown data. While the file encodes this as a list (e.g. [-1,0]), this will get read in as a string object. You'll need to do a little bit of parsing to make use of it to identify and clean the data. Convert data that matches a 'missing' or 'unknown' value code into a numpy NaN value. You might want to see how much data takes on a 'missing' or 'unknown' code, and how much data is naturally missing, as a point of interest.

As one more reminder, you are encouraged to add additional cells to break up your analysis into manageable chunks.

In [ ]:
# Identify missing or unknown data values and convert them to NaNs.

#FeatureSummary['missing_or_unknown']=FeatureSummary['missing_or_unknown'].apply(lambda x : eval(x))

for attribute , missValue in FeatureSummary[['attribute' ,'missing_or_unknown' ]].values :
        missValue=missValue[1:-1]
        missValue = missValue.split(',')
        for x in  missValue  : 
            try :
                demographicData[attribute].replace(int(x),np.NAN , inplace=True)  
            except :
                demographicData[attribute].replace(x ,np.NAN , inplace=True)

Step 1.1.2: Assess Missing Data in Each Column¶

How much missing data is present in each column? There are a few columns that are outliers in terms of the proportion of values that are missing. You will want to use matplotlib's hist() function to visualize the distribution of missing value counts to find these columns. Identify and document these columns. While some of these columns might have justifications for keeping or re-encoding the data, for this project you should just remove them from the dataframe. (Feel free to make remarks about these outlier columns in the discussion, however!)

For the remaining features, are there any patterns in which columns have, or share, missing data?

In [ ]:
# Perform an assessment of how much missing data there is in each column of the

missingValuepercent=demographicData.isna().sum()/len(demographicData)*100
 
missingValuepercent
Out[ ]:
AGER_TYP                 76.955435
ALTERSKATEGORIE_GROB      0.323264
ANREDE_KZ                 0.000000
CJT_GESAMTTYP             0.544646
FINANZ_MINIMALIST         0.000000
FINANZ_SPARER             0.000000
FINANZ_VORSORGER          0.000000
FINANZ_ANLEGER            0.000000
FINANZ_UNAUFFAELLIGER     0.000000
FINANZ_HAUSBAUER          0.000000
FINANZTYP                 0.000000
GEBURTSJAHR              44.020282
GFK_URLAUBERTYP           0.544646
GREEN_AVANTGARDE          0.000000
HEALTH_TYP               12.476816
LP_LEBENSPHASE_FEIN      10.954859
LP_LEBENSPHASE_GROB      10.611509
LP_FAMILIE_FEIN           8.728699
LP_FAMILIE_GROB           8.728699
LP_STATUS_FEIN            0.544646
LP_STATUS_GROB            0.544646
NATIONALITAET_KZ         12.153551
PRAEGENDE_JUGENDJAHRE    12.136608
RETOURTYP_BK_S            0.544646
SEMIO_SOZ                 0.000000
SEMIO_FAM                 0.000000
SEMIO_REL                 0.000000
SEMIO_MAT                 0.000000
SEMIO_VERT                0.000000
SEMIO_LUST                0.000000
SEMIO_ERL                 0.000000
SEMIO_KULT                0.000000
SEMIO_RAT                 0.000000
SEMIO_KRIT                0.000000
SEMIO_DOM                 0.000000
SEMIO_KAEM                0.000000
SEMIO_PFLICHT             0.000000
SEMIO_TRADV               0.000000
SHOPPER_TYP              12.476816
SOHO_KZ                   8.247000
TITEL_KZ                 99.757636
VERS_TYP                 12.476816
ZABEOTYP                  0.000000
ALTER_HH                 34.813699
ANZ_PERSONEN              8.247000
ANZ_TITEL                 8.247000
HH_EINKOMMEN_SCORE        2.058749
KK_KUNDENTYP             65.596749
W_KEIT_KIND_HH           16.605084
WOHNDAUER_2008            8.247000
ANZ_HAUSHALTE_AKTIV      11.176913
ANZ_HH_TITEL             10.884842
GEBAEUDETYP              10.451729
KONSUMNAEHE               8.299737
MIN_GEBAEUDEJAHR         10.451729
OST_WEST_KZ              10.451729
WOHNLAGE                 10.451729
CAMEO_DEUG_2015          11.147852
CAMEO_DEU_2015           11.147852
CAMEO_INTL_2015          11.147852
KBA05_ANTG1              14.959701
KBA05_ANTG2              14.959701
KBA05_ANTG3              14.959701
KBA05_ANTG4              14.959701
KBA05_BAUMAX             53.468668
KBA05_GBZ                14.959701
BALLRAUM                 10.518154
EWDICHTE                 10.518154
INNENSTADT               10.518154
GEBAEUDETYP_RASTER       10.452514
KKK                      17.735668
MOBI_REGIO               14.959701
ONLINE_AFFINITAET         0.544646
REGIOTYP                 17.735668
KBA13_ANZAHL_PKW         11.871354
PLZ8_ANTG1               13.073637
PLZ8_ANTG2               13.073637
PLZ8_ANTG3               13.073637
PLZ8_ANTG4               13.073637
PLZ8_BAUMAX              13.073637
PLZ8_HHZ                 13.073637
PLZ8_GBZ                 13.073637
ARBEIT                   10.926022
ORTSGR_KLS9              10.914689
RELAT_AB                 10.926022
dtype: float64
In [ ]:
# Investigate patterns in the amount of missing data in each column.
plt.figure(figsize=(20,10))
plt.bar(missingValuepercent.index , missingValuepercent.values , )
plt.ylabel('percetage of the missing/unkown values')
plt.show()
In [ ]:
# Remove the outlier columns from the dataset. (You'll perform other data
# engineering tasks such as re-encoding and imputation later.)

outier_columns=missingValuepercent[missingValuepercent>20].index

#removing outlier from FeatureSummary
outlierMask=[x not in outier_columns for x in  FeatureSummary['attribute'].values]
FeatureSummary=FeatureSummary[outlierMask]

#removing outlier from demographicData
demographicData.drop(outier_columns , axis=1 ,inplace=True)
In [ ]:
 
demographicData.isna().sum().sum()
outier_columns
Out[ ]:
Index(['AGER_TYP', 'GEBURTSJAHR', 'TITEL_KZ', 'ALTER_HH', 'KK_KUNDENTYP',
       'KBA05_BAUMAX'],
      dtype='object')

Discussion 1.1.2: Assess Missing Data in Each Column¶

(Double click this cell and replace this text with your own text, reporting your observations regarding the amount of missing data in each column. Are there any patterns in missing values? Which columns were removed from the dataset?)

KK_KUNDENTYP this feature has more than 60% of unkown or missing , it will be dropped

other features has around 10% NANs

Step 1.1.3: Assess Missing Data in Each Row¶

Now, you'll perform a similar assessment for the rows of the dataset. How much data is missing in each row? As with the columns, you should see some groups of points that have a very different numbers of missing values. Divide the data into two subsets: one for data points that are above some threshold for missing values, and a second subset for points below that threshold.

In order to know what to do with the outlier rows, we should see if the distribution of data values on columns that are not missing data (or are missing very little data) are similar or different between the two groups. Select at least five of these columns and compare the distribution of values.

  • You can use seaborn's countplot() function to create a bar chart of code frequencies and matplotlib's subplot() function to put bar charts for the two subplots side by side.
  • To reduce repeated code, you might want to write a function that can perform this comparison, taking as one of its arguments a column to be compared.

Depending on what you observe in your comparison, this will have implications on how you approach your conclusions later in the analysis. If the distributions of non-missing features look similar between the data with many missing values and the data with few or no missing values, then we could argue that simply dropping those points from the analysis won't present a major issue. On the other hand, if the data with many missing values looks very different from the data with few or no missing values, then we should make a note on those data as special. We'll revisit these data later on. Either way, you should continue your analysis for now using just the subset of the data with few or no missing values.

In [ ]:
# How much data is missing in each row of the dataset?
row_missingValue=demographicData.isna().sum(axis=1)  
print(row_missingValue.unique())
plt.figure()
plt.hist(row_missingValue)
plt.show()
[43  0  7 47  6  8  3 10  5 19  2 34  4 40  1 45 29 17 16 15  9 13 38 11
 33 35 14 27 18 25 24 37 12 39 44 20 23 41 32 22 21 36 26 42 28 31 30 48
 49]
In [ ]:
# Write code to divide the data into two subsets based on the number of missing
# values in each row.
#the optuimum value for the cut is 10 to 20 
# I will choose 10
threshold=10
little_nans=demographicData[ row_missingValue<threshold]
alot_nans=demographicData[ row_missingValue>threshold] 
In [ ]:
# Compare the distribution of values for at least five columns where there are
# no or few missing values, between the two subsets.
 
for clm in little_nans.columns[:10] :
    fig, axes = plt.subplots(1, 2, figsize=(15, 5)   )
    fig.suptitle('Initial Pokemon - 1st Generation')

    # Bulbasaur
    sns.countplot(ax=axes[0], data=little_nans ,
                  x=clm)
    axes[0].set_title(f'litle nans {clm}  ')

    # Charmander
    sns.countplot(ax=axes[1],data=alot_nans ,
                  x= clm)
    axes[1].set_title(f'alot nans {clm}  ')

    plt.show()

Discussion 1.1.3: Assess Missing Data in Each Row¶

(Double-click this cell and replace this text with your own text, reporting your observations regarding missing data in rows. Are the data with lots of missing values are qualitatively different from data with few or no missing values?)

the data with litle Nans doesnot have the same distribution for the data with alot of nans

so we continue with the data with the little amount of NAN

Step 1.2: Select and Re-Encode Features¶

Checking for missing data isn't the only way in which you can prepare a dataset for analysis. Since the unsupervised learning techniques to be used will only work on data that is encoded numerically, you need to make a few encoding changes or additional assumptions to be able to make progress. In addition, while almost all of the values in the dataset are encoded using numbers, not all of them represent numeric values. Check the third column of the feature summary (feat_info) for a summary of types of measurement.

  • For numeric and interval data, these features can be kept without changes.
  • Most of the variables in the dataset are ordinal in nature. While ordinal values may technically be non-linear in spacing, make the simplifying assumption that the ordinal variables can be treated as being interval in nature (that is, kept without any changes).
  • Special handling may be necessary for the remaining two variable types: categorical, and 'mixed'.

In the first two parts of this sub-step, you will perform an investigation of the categorical and mixed-type features and make a decision on each of them, whether you will keep, drop, or re-encode each. Then, in the last part, you will create a new data frame with only the selected and engineered columns.

Data wrangling is often the trickiest part of the data analysis process, and there's a lot of it to be done here. But stick with it: once you're done with this step, you'll be ready to get to the machine learning parts of the project!

In [ ]:
# How many features are there of each data type?
mixedFeatures=FeatureSummary['attribute'].loc[FeatureSummary['type']=='mixed']
mixedFeatures=mixedFeatures.values

print('counting the feature of each type')
print(FeatureSummary['type'].value_counts())

print('Mixed Features :' )
print(mixedFeatures)
counting the feature of each type
type
ordinal        49
categorical    18
mixed           6
numeric         6
Name: count, dtype: int64
Mixed Features :
['LP_LEBENSPHASE_FEIN' 'LP_LEBENSPHASE_GROB' 'PRAEGENDE_JUGENDJAHRE'
 'WOHNLAGE' 'CAMEO_INTL_2015' 'PLZ8_BAUMAX']

Step 1.2.1: Re-Encode Categorical Features¶

For categorical data, you would ordinarily need to encode the levels as dummy variables. Depending on the number of categories, perform one of the following:

  • For binary (two-level) categoricals that take numeric values, you can keep them without needing to do anything.
  • There is one binary variable that takes on non-numeric values. For this one, you need to re-encode the values as numbers or create a dummy variable.
  • For multi-level categoricals (three or more values), you can choose to encode the values using multiple dummy variables (e.g. via OneHotEncoder), or (to keep things straightforward) just drop them from the analysis. As always, document your choices in the Discussion section.
In [ ]:
FeatureSummary[FeatureSummary['attribute']=='PRAEGENDE_JUGENDJAHRE']
Out[ ]:
attribute information_level type missing_or_unknown
22 PRAEGENDE_JUGENDJAHRE person mixed [-1,0]
In [ ]:
# Assess categorical variables: which are binary, which are multi-level, and
# which one needs to be re-encoded?

multi_level_features=[]
binary_level_features=[]
 
catfeatures=FeatureSummary.loc[ FeatureSummary['type']=='categorical'   ]
 
for att in catfeatures['attribute'] : 
    levels=len(little_nans[att].value_counts() )
    if levels <=2 :
        binary_level_features.append(att)
    else :
        multi_level_features.append(att)
        
In [ ]:
# Re-encode categorical variable(s) to be kept in the analysis.

data=pd.get_dummies(little_nans,  
                    dummy_na=False, columns=multi_level_features)
data.dropna(inplace=True)
In [ ]:
data['PRAEGENDE_JUGENDJAHRE'].unique()
Out[ ]:
array([14., 15.,  8.,  3., 10., 11.,  9.,  5.,  4.,  2.,  6.,  1., 12.,
       13.,  7.])

Discussion 1.2.1: Re-Encode Categorical Features¶

(Double-click this cell and replace this text with your own text, reporting your findings and decisions regarding categorical features. Which ones did you keep, which did you drop, and what engineering steps did you perform?)

have decided to OneHotEncoder for the mulit level categorial variable if we drop them , we will loss data which might be crucial for the model so it is better to encode them and utilise a dimensionality reduction technique

Step 1.2.2: Engineer Mixed-Type Features¶

There are a handful of features that are marked as "mixed" in the feature summary that require special treatment in order to be included in the analysis. There are two in particular that deserve attention; the handling of the rest are up to your own choices:

  • "PRAEGENDE_JUGENDJAHRE" combines information on three dimensions: generation by decade, movement (mainstream vs. avantgarde), and nation (east vs. west). While there aren't enough levels to disentangle east from west, you should create two new variables to capture the other two dimensions: an interval-type variable for decade, and a binary variable for movement.
  • "CAMEO_INTL_2015" combines information on two axes: wealth and life stage. Break up the two-digit codes by their 'tens'-place and 'ones'-place digits into two new ordinal variables (which, for the purposes of this project, is equivalent to just treating them as their raw numeric values).
  • If you decide to keep or engineer new features around the other mixed-type features, make sure you note your steps in the Discussion section.

Be sure to check Data_Dictionary.md for the details needed to finish these tasks.

In [ ]:
# Investigate "PRAEGENDE_JUGENDJAHRE" and engineer two new variables.
def PRAEGENDE_JUGENDJAHRE_features (x)  :
        PRAEGENDE_JUGENDJAHRE_labels={ 
          1: '40s - war years (Mainstream, E+W)',
          2: '40s - reconstruction years (Avantgarde, E+W)',
          3: '50s - economic miracle (Mainstream, E+W)',
          4: '50s - milk bar / Individualisation (Avantgarde, E+W)',
          5: '60s - economic miracle (Mainstream, E+W)',
          6: '60s - generation 68 / student protestors (Avantgarde, W)',
          7: '60s - opponents to the building of the Wall (Avantgarde, E)',
          8: '70s - family orientation (Mainstream, E+W)',
          9: '70s - peace movement (Avantgarde, E+W)',
         10: '80s - Generation Golf (Mainstream, W)',
         11: '80s - ecological awareness (Avantgarde, W)',
         12: '80s - FDJ / communist party youth organisation (Mainstream, E)',
         13: '80s - Swords into ploughshares (Avantgarde, E)',
         14: '90s - digital media kids (Mainstream, E+W)',
         15: '90s - ecological awareness (Avantgarde, E+W)'}
        
        Extractedfeatures=PRAEGENDE_JUGENDJAHRE_labels[x]
        generation=Extractedfeatures[:2]
        movement='Mainstream' if 'Mainstream' in Extractedfeatures else 'Avantgarde' 
        
        if  ' E)' in Extractedfeatures : 
            nation='E'
        elif ' W)' in Extractedfeatures : 
            nation='W'
        elif ' E+W)' in Extractedfeatures : 
            nation='EW'
    
        return [generation , movement ,nation]

def features_PRAEGENDE_postProcess(data) :
    features_PRAEGENDE=data['PRAEGENDE_JUGENDJAHRE'].apply(PRAEGENDE_JUGENDJAHRE_features)
    features_PRAEGENDE=pd.DataFrame(list(features_PRAEGENDE),columns=['generation' , 'movement' ,'nation']) 
    features_PRAEGENDE=pd.get_dummies(features_PRAEGENDE,dummy_na=False, columns=[ 'movement' ,'nation'])
    return features_PRAEGENDE

features_PRAEGENDE=features_PRAEGENDE_postProcess(data)
In [ ]:
# Investigate "CAMEO_INTL_2015" and engineer two new variables.
def CAMEO_INTL_featrues(data) :
    CAMEO_INTL=list(data["CAMEO_INTL_2015"].astype('str').apply(lambda x : [x[0],x[1]]) )
    CAMEO_INTL_df=pd.DataFrame(CAMEO_INTL,columns=['tens','ones'])
    return CAMEO_INTL_df

CAMEO_INTL_df=CAMEO_INTL_featrues(data)

data=pd.concat([data,features_PRAEGENDE,CAMEO_INTL_df],axis=1) 

 
data.head()
Out[ ]:
ALTERSKATEGORIE_GROB ANREDE_KZ FINANZ_MINIMALIST FINANZ_SPARER FINANZ_VORSORGER FINANZ_ANLEGER FINANZ_UNAUFFAELLIGER FINANZ_HAUSBAUER GREEN_AVANTGARDE HEALTH_TYP LP_LEBENSPHASE_FEIN LP_LEBENSPHASE_GROB PRAEGENDE_JUGENDJAHRE RETOURTYP_BK_S SEMIO_SOZ SEMIO_FAM SEMIO_REL SEMIO_MAT SEMIO_VERT SEMIO_LUST SEMIO_ERL SEMIO_KULT SEMIO_RAT SEMIO_KRIT SEMIO_DOM SEMIO_KAEM SEMIO_PFLICHT SEMIO_TRADV SOHO_KZ VERS_TYP ANZ_PERSONEN ANZ_TITEL HH_EINKOMMEN_SCORE W_KEIT_KIND_HH WOHNDAUER_2008 ANZ_HAUSHALTE_AKTIV ANZ_HH_TITEL KONSUMNAEHE MIN_GEBAEUDEJAHR OST_WEST_KZ WOHNLAGE CAMEO_INTL_2015 KBA05_ANTG1 KBA05_ANTG2 KBA05_ANTG3 KBA05_ANTG4 KBA05_GBZ BALLRAUM EWDICHTE INNENSTADT GEBAEUDETYP_RASTER KKK MOBI_REGIO ONLINE_AFFINITAET REGIOTYP KBA13_ANZAHL_PKW PLZ8_ANTG1 PLZ8_ANTG2 PLZ8_ANTG3 PLZ8_ANTG4 PLZ8_BAUMAX PLZ8_HHZ PLZ8_GBZ ARBEIT ORTSGR_KLS9 RELAT_AB CJT_GESAMTTYP_1.0 CJT_GESAMTTYP_2.0 CJT_GESAMTTYP_3.0 CJT_GESAMTTYP_4.0 CJT_GESAMTTYP_5.0 CJT_GESAMTTYP_6.0 FINANZTYP_1 FINANZTYP_2 FINANZTYP_3 FINANZTYP_4 FINANZTYP_5 FINANZTYP_6 GFK_URLAUBERTYP_1.0 GFK_URLAUBERTYP_2.0 GFK_URLAUBERTYP_3.0 GFK_URLAUBERTYP_4.0 GFK_URLAUBERTYP_5.0 GFK_URLAUBERTYP_6.0 GFK_URLAUBERTYP_7.0 GFK_URLAUBERTYP_8.0 GFK_URLAUBERTYP_9.0 GFK_URLAUBERTYP_10.0 GFK_URLAUBERTYP_11.0 GFK_URLAUBERTYP_12.0 LP_FAMILIE_FEIN_1.0 LP_FAMILIE_FEIN_2.0 LP_FAMILIE_FEIN_3.0 LP_FAMILIE_FEIN_4.0 LP_FAMILIE_FEIN_5.0 LP_FAMILIE_FEIN_6.0 LP_FAMILIE_FEIN_7.0 LP_FAMILIE_FEIN_8.0 LP_FAMILIE_FEIN_9.0 LP_FAMILIE_FEIN_10.0 LP_FAMILIE_FEIN_11.0 LP_FAMILIE_GROB_1.0 LP_FAMILIE_GROB_2.0 LP_FAMILIE_GROB_3.0 LP_FAMILIE_GROB_4.0 LP_FAMILIE_GROB_5.0 LP_STATUS_FEIN_1.0 LP_STATUS_FEIN_2.0 LP_STATUS_FEIN_3.0 LP_STATUS_FEIN_4.0 LP_STATUS_FEIN_5.0 LP_STATUS_FEIN_6.0 LP_STATUS_FEIN_7.0 LP_STATUS_FEIN_8.0 LP_STATUS_FEIN_9.0 LP_STATUS_FEIN_10.0 LP_STATUS_GROB_1.0 LP_STATUS_GROB_2.0 LP_STATUS_GROB_3.0 LP_STATUS_GROB_4.0 LP_STATUS_GROB_5.0 NATIONALITAET_KZ_1.0 NATIONALITAET_KZ_2.0 NATIONALITAET_KZ_3.0 SHOPPER_TYP_0.0 SHOPPER_TYP_1.0 SHOPPER_TYP_2.0 SHOPPER_TYP_3.0 ZABEOTYP_1 ZABEOTYP_2 ZABEOTYP_3 ZABEOTYP_4 ZABEOTYP_5 ZABEOTYP_6 GEBAEUDETYP_1.0 GEBAEUDETYP_2.0 GEBAEUDETYP_3.0 GEBAEUDETYP_4.0 GEBAEUDETYP_5.0 GEBAEUDETYP_6.0 GEBAEUDETYP_8.0 CAMEO_DEUG_2015_1 CAMEO_DEUG_2015_2 CAMEO_DEUG_2015_3 CAMEO_DEUG_2015_4 CAMEO_DEUG_2015_5 CAMEO_DEUG_2015_6 CAMEO_DEUG_2015_7 CAMEO_DEUG_2015_8 CAMEO_DEUG_2015_9 CAMEO_DEU_2015_1A CAMEO_DEU_2015_1B CAMEO_DEU_2015_1C CAMEO_DEU_2015_1D CAMEO_DEU_2015_1E CAMEO_DEU_2015_2A CAMEO_DEU_2015_2B CAMEO_DEU_2015_2C CAMEO_DEU_2015_2D CAMEO_DEU_2015_3A CAMEO_DEU_2015_3B CAMEO_DEU_2015_3C CAMEO_DEU_2015_3D CAMEO_DEU_2015_4A CAMEO_DEU_2015_4B CAMEO_DEU_2015_4C CAMEO_DEU_2015_4D CAMEO_DEU_2015_4E CAMEO_DEU_2015_5A CAMEO_DEU_2015_5B CAMEO_DEU_2015_5C CAMEO_DEU_2015_5D CAMEO_DEU_2015_5E CAMEO_DEU_2015_5F CAMEO_DEU_2015_6A CAMEO_DEU_2015_6B CAMEO_DEU_2015_6C CAMEO_DEU_2015_6D CAMEO_DEU_2015_6E CAMEO_DEU_2015_6F CAMEO_DEU_2015_7A CAMEO_DEU_2015_7B CAMEO_DEU_2015_7C CAMEO_DEU_2015_7D CAMEO_DEU_2015_7E CAMEO_DEU_2015_8A CAMEO_DEU_2015_8B CAMEO_DEU_2015_8C CAMEO_DEU_2015_8D CAMEO_DEU_2015_9A CAMEO_DEU_2015_9B CAMEO_DEU_2015_9C CAMEO_DEU_2015_9D CAMEO_DEU_2015_9E generation movement_Avantgarde movement_Mainstream nation_E nation_EW nation_W tens ones
1 1.0 2.0 1.0 5.0 2.0 5.0 4.0 5.0 0.0 3.0 21.0 6.0 14.0 1.0 5.0 4.0 4.0 3.0 1.0 2.0 2.0 3.0 6.0 4.0 7.0 4.0 7.0 6.0 1.0 2.0 2.0 0.0 6.0 3.0 9.0 11.0 0.0 1.0 1992.0 W 4.0 51 0.0 0.0 0.0 2.0 1.0 6.0 3.0 8.0 3.0 2.0 1.0 3.0 3.0 963.0 2.0 3.0 2.0 1.0 1.0 5.0 4.0 3.0 5.0 4.0 False False False False True False True False False False False False False False False False False False False False False True False False False False False False True False False False False False False False False True False False False True False False False False False False False False True False False False False True False False False False False True False False False False True False False False False False False False True False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True False False False False False False False False 90 True False False True False 2 4
2 3.0 2.0 1.0 4.0 1.0 2.0 3.0 5.0 1.0 3.0 3.0 1.0 15.0 3.0 4.0 1.0 3.0 3.0 4.0 4.0 6.0 3.0 4.0 7.0 7.0 7.0 3.0 3.0 0.0 1.0 1.0 0.0 4.0 3.0 9.0 10.0 0.0 5.0 1992.0 W 2.0 24 1.0 3.0 1.0 0.0 3.0 2.0 4.0 4.0 4.0 2.0 3.0 2.0 2.0 712.0 3.0 3.0 1.0 0.0 1.0 4.0 4.0 3.0 5.0 2.0 False False True False False False True False False False False False False False False False False False False False False True False False True False False False False False False False False False False True False False False False False False True False False False False False False False False True False False False True False False False False True False False False False False True False True False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False 70 False True False True False 4 3
4 3.0 1.0 4.0 3.0 4.0 1.0 3.0 2.0 0.0 3.0 32.0 10.0 8.0 5.0 6.0 4.0 4.0 2.0 7.0 4.0 4.0 6.0 2.0 3.0 2.0 2.0 4.0 2.0 0.0 2.0 4.0 0.0 5.0 2.0 9.0 3.0 0.0 4.0 1992.0 W 3.0 43 1.0 4.0 1.0 0.0 3.0 2.0 5.0 1.0 5.0 3.0 3.0 5.0 5.0 435.0 2.0 4.0 2.0 1.0 2.0 3.0 3.0 4.0 6.0 5.0 False False False False True False False False False False True False False False False False True False False False False False False False False False False False False False False False False True False False False False False True False False True False False False False False False False False True False False False True False False False False True False False False False True False False True False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False 80 False True False False True 2 2
5 1.0 2.0 3.0 1.0 5.0 2.0 2.0 5.0 0.0 3.0 8.0 2.0 3.0 3.0 2.0 4.0 7.0 4.0 2.0 2.0 2.0 5.0 7.0 4.0 4.0 4.0 7.0 6.0 0.0 2.0 1.0 0.0 5.0 6.0 9.0 5.0 0.0 5.0 1992.0 W 7.0 54 2.0 2.0 0.0 0.0 4.0 6.0 2.0 7.0 4.0 4.0 4.0 1.0 5.0 1300.0 2.0 3.0 1.0 1.0 1.0 5.0 5.0 2.0 3.0 3.0 False True False False False False False True False False False False True False False False False False False False False False False False True False False False False False False False False False False True False False False False False False False True False False False False False False False True False False False True False False True False False False False False False True False False True False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True False False False False False False 70 False True False True False 1 4
6 2.0 2.0 1.0 5.0 1.0 5.0 4.0 3.0 0.0 2.0 2.0 1.0 10.0 4.0 2.0 5.0 5.0 7.0 2.0 6.0 5.0 5.0 7.0 7.0 4.0 7.0 7.0 7.0 0.0 1.0 1.0 0.0 6.0 3.0 9.0 4.0 0.0 5.0 1992.0 W 5.0 22 3.0 2.0 0.0 0.0 3.0 6.0 4.0 3.0 5.0 3.0 5.0 2.0 5.0 867.0 3.0 3.0 1.0 0.0 1.0 5.0 5.0 4.0 6.0 3.0 False False False False True False False False False True False False False False False False False False False False False False False True True False False False False False False False False False False True False False False False False True False False False False False False False False True False False False False True False False False True False False False False False True False False True False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False 80 True False False False True 1 3

Discussion 1.2.2: Engineer Mixed-Type Features¶

(Double-click this cell and replace this text with your own text, reporting your findings and decisions regarding mixed-value features. Which ones did you keep, which did you drop, and what engineering steps did you perform?)

kept "PRAEGENDE_JUGENDJAHRE" features however converted this columns to 3 features:

  • 1- generation : ordinal value for the century 40-90 ,
  • 2- movement : Mainstream and Avantgarde then one-hot encoded to two binary columns
  • 3- nation : Easet and West then one-hot encoded to two binary columns

kept "CAMEO_INTL_2015" features seperated the values to two ordinal features

  • ones
  • tens

the rest of the Mixed features were dropped since it is less relavant

Step 1.2.3: Complete Feature Selection¶

In order to finish this step up, you need to make sure that your data frame now only has the columns that you want to keep. To summarize, the dataframe should consist of the following:

  • All numeric, interval, and ordinal type columns from the original dataset.
  • Binary categorical features (all numerically-encoded).
  • Engineered features from other multi-level categorical features and mixed features.

Make sure that for any new columns that you have engineered, that you've excluded the original columns from the final dataset. Otherwise, their values will interfere with the analysis later on the project. For example, you should not keep "PRAEGENDE_JUGENDJAHRE", since its values won't be useful for the algorithm: only the values derived from it in the engineered features you created should be retained. As a reminder, your data should only be from the subset with few or no missing values.

In [ ]:
# If there are other re-engineering tasks you need to perform, make sure you
# take care of them here. (Dealing with missing data will come in step 2.1.)
#dropping all the mixed features 
data.drop(mixedFeatures,axis=1 , inplace=True)
data.head()
Out[ ]:
ALTERSKATEGORIE_GROB ANREDE_KZ FINANZ_MINIMALIST FINANZ_SPARER FINANZ_VORSORGER FINANZ_ANLEGER FINANZ_UNAUFFAELLIGER FINANZ_HAUSBAUER GREEN_AVANTGARDE HEALTH_TYP RETOURTYP_BK_S SEMIO_SOZ SEMIO_FAM SEMIO_REL SEMIO_MAT SEMIO_VERT SEMIO_LUST SEMIO_ERL SEMIO_KULT SEMIO_RAT SEMIO_KRIT SEMIO_DOM SEMIO_KAEM SEMIO_PFLICHT SEMIO_TRADV SOHO_KZ VERS_TYP ANZ_PERSONEN ANZ_TITEL HH_EINKOMMEN_SCORE W_KEIT_KIND_HH WOHNDAUER_2008 ANZ_HAUSHALTE_AKTIV ANZ_HH_TITEL KONSUMNAEHE MIN_GEBAEUDEJAHR OST_WEST_KZ KBA05_ANTG1 KBA05_ANTG2 KBA05_ANTG3 KBA05_ANTG4 KBA05_GBZ BALLRAUM EWDICHTE INNENSTADT GEBAEUDETYP_RASTER KKK MOBI_REGIO ONLINE_AFFINITAET REGIOTYP KBA13_ANZAHL_PKW PLZ8_ANTG1 PLZ8_ANTG2 PLZ8_ANTG3 PLZ8_ANTG4 PLZ8_HHZ PLZ8_GBZ ARBEIT ORTSGR_KLS9 RELAT_AB CJT_GESAMTTYP_1.0 CJT_GESAMTTYP_2.0 CJT_GESAMTTYP_3.0 CJT_GESAMTTYP_4.0 CJT_GESAMTTYP_5.0 CJT_GESAMTTYP_6.0 FINANZTYP_1 FINANZTYP_2 FINANZTYP_3 FINANZTYP_4 FINANZTYP_5 FINANZTYP_6 GFK_URLAUBERTYP_1.0 GFK_URLAUBERTYP_2.0 GFK_URLAUBERTYP_3.0 GFK_URLAUBERTYP_4.0 GFK_URLAUBERTYP_5.0 GFK_URLAUBERTYP_6.0 GFK_URLAUBERTYP_7.0 GFK_URLAUBERTYP_8.0 GFK_URLAUBERTYP_9.0 GFK_URLAUBERTYP_10.0 GFK_URLAUBERTYP_11.0 GFK_URLAUBERTYP_12.0 LP_FAMILIE_FEIN_1.0 LP_FAMILIE_FEIN_2.0 LP_FAMILIE_FEIN_3.0 LP_FAMILIE_FEIN_4.0 LP_FAMILIE_FEIN_5.0 LP_FAMILIE_FEIN_6.0 LP_FAMILIE_FEIN_7.0 LP_FAMILIE_FEIN_8.0 LP_FAMILIE_FEIN_9.0 LP_FAMILIE_FEIN_10.0 LP_FAMILIE_FEIN_11.0 LP_FAMILIE_GROB_1.0 LP_FAMILIE_GROB_2.0 LP_FAMILIE_GROB_3.0 LP_FAMILIE_GROB_4.0 LP_FAMILIE_GROB_5.0 LP_STATUS_FEIN_1.0 LP_STATUS_FEIN_2.0 LP_STATUS_FEIN_3.0 LP_STATUS_FEIN_4.0 LP_STATUS_FEIN_5.0 LP_STATUS_FEIN_6.0 LP_STATUS_FEIN_7.0 LP_STATUS_FEIN_8.0 LP_STATUS_FEIN_9.0 LP_STATUS_FEIN_10.0 LP_STATUS_GROB_1.0 LP_STATUS_GROB_2.0 LP_STATUS_GROB_3.0 LP_STATUS_GROB_4.0 LP_STATUS_GROB_5.0 NATIONALITAET_KZ_1.0 NATIONALITAET_KZ_2.0 NATIONALITAET_KZ_3.0 SHOPPER_TYP_0.0 SHOPPER_TYP_1.0 SHOPPER_TYP_2.0 SHOPPER_TYP_3.0 ZABEOTYP_1 ZABEOTYP_2 ZABEOTYP_3 ZABEOTYP_4 ZABEOTYP_5 ZABEOTYP_6 GEBAEUDETYP_1.0 GEBAEUDETYP_2.0 GEBAEUDETYP_3.0 GEBAEUDETYP_4.0 GEBAEUDETYP_5.0 GEBAEUDETYP_6.0 GEBAEUDETYP_8.0 CAMEO_DEUG_2015_1 CAMEO_DEUG_2015_2 CAMEO_DEUG_2015_3 CAMEO_DEUG_2015_4 CAMEO_DEUG_2015_5 CAMEO_DEUG_2015_6 CAMEO_DEUG_2015_7 CAMEO_DEUG_2015_8 CAMEO_DEUG_2015_9 CAMEO_DEU_2015_1A CAMEO_DEU_2015_1B CAMEO_DEU_2015_1C CAMEO_DEU_2015_1D CAMEO_DEU_2015_1E CAMEO_DEU_2015_2A CAMEO_DEU_2015_2B CAMEO_DEU_2015_2C CAMEO_DEU_2015_2D CAMEO_DEU_2015_3A CAMEO_DEU_2015_3B CAMEO_DEU_2015_3C CAMEO_DEU_2015_3D CAMEO_DEU_2015_4A CAMEO_DEU_2015_4B CAMEO_DEU_2015_4C CAMEO_DEU_2015_4D CAMEO_DEU_2015_4E CAMEO_DEU_2015_5A CAMEO_DEU_2015_5B CAMEO_DEU_2015_5C CAMEO_DEU_2015_5D CAMEO_DEU_2015_5E CAMEO_DEU_2015_5F CAMEO_DEU_2015_6A CAMEO_DEU_2015_6B CAMEO_DEU_2015_6C CAMEO_DEU_2015_6D CAMEO_DEU_2015_6E CAMEO_DEU_2015_6F CAMEO_DEU_2015_7A CAMEO_DEU_2015_7B CAMEO_DEU_2015_7C CAMEO_DEU_2015_7D CAMEO_DEU_2015_7E CAMEO_DEU_2015_8A CAMEO_DEU_2015_8B CAMEO_DEU_2015_8C CAMEO_DEU_2015_8D CAMEO_DEU_2015_9A CAMEO_DEU_2015_9B CAMEO_DEU_2015_9C CAMEO_DEU_2015_9D CAMEO_DEU_2015_9E generation movement_Avantgarde movement_Mainstream nation_E nation_EW nation_W tens ones
1 1.0 2.0 1.0 5.0 2.0 5.0 4.0 5.0 0.0 3.0 1.0 5.0 4.0 4.0 3.0 1.0 2.0 2.0 3.0 6.0 4.0 7.0 4.0 7.0 6.0 1.0 2.0 2.0 0.0 6.0 3.0 9.0 11.0 0.0 1.0 1992.0 W 0.0 0.0 0.0 2.0 1.0 6.0 3.0 8.0 3.0 2.0 1.0 3.0 3.0 963.0 2.0 3.0 2.0 1.0 5.0 4.0 3.0 5.0 4.0 False False False False True False True False False False False False False False False False False False False False False True False False False False False False True False False False False False False False False True False False False True False False False False False False False False True False False False False True False False False False False True False False False False True False False False False False False False True False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True False False False False False False False False 90 True False False True False 2 4
2 3.0 2.0 1.0 4.0 1.0 2.0 3.0 5.0 1.0 3.0 3.0 4.0 1.0 3.0 3.0 4.0 4.0 6.0 3.0 4.0 7.0 7.0 7.0 3.0 3.0 0.0 1.0 1.0 0.0 4.0 3.0 9.0 10.0 0.0 5.0 1992.0 W 1.0 3.0 1.0 0.0 3.0 2.0 4.0 4.0 4.0 2.0 3.0 2.0 2.0 712.0 3.0 3.0 1.0 0.0 4.0 4.0 3.0 5.0 2.0 False False True False False False True False False False False False False False False False False False False False False True False False True False False False False False False False False False False True False False False False False False True False False False False False False False False True False False False True False False False False True False False False False False True False True False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False 70 False True False True False 4 3
4 3.0 1.0 4.0 3.0 4.0 1.0 3.0 2.0 0.0 3.0 5.0 6.0 4.0 4.0 2.0 7.0 4.0 4.0 6.0 2.0 3.0 2.0 2.0 4.0 2.0 0.0 2.0 4.0 0.0 5.0 2.0 9.0 3.0 0.0 4.0 1992.0 W 1.0 4.0 1.0 0.0 3.0 2.0 5.0 1.0 5.0 3.0 3.0 5.0 5.0 435.0 2.0 4.0 2.0 1.0 3.0 3.0 4.0 6.0 5.0 False False False False True False False False False False True False False False False False True False False False False False False False False False False False False False False False False True False False False False False True False False True False False False False False False False False True False False False True False False False False True False False False False True False False True False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False 80 False True False False True 2 2
5 1.0 2.0 3.0 1.0 5.0 2.0 2.0 5.0 0.0 3.0 3.0 2.0 4.0 7.0 4.0 2.0 2.0 2.0 5.0 7.0 4.0 4.0 4.0 7.0 6.0 0.0 2.0 1.0 0.0 5.0 6.0 9.0 5.0 0.0 5.0 1992.0 W 2.0 2.0 0.0 0.0 4.0 6.0 2.0 7.0 4.0 4.0 4.0 1.0 5.0 1300.0 2.0 3.0 1.0 1.0 5.0 5.0 2.0 3.0 3.0 False True False False False False False True False False False False True False False False False False False False False False False False True False False False False False False False False False False True False False False False False False False True False False False False False False False True False False False True False False True False False False False False False True False False True False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True False False False False False False 70 False True False True False 1 4
6 2.0 2.0 1.0 5.0 1.0 5.0 4.0 3.0 0.0 2.0 4.0 2.0 5.0 5.0 7.0 2.0 6.0 5.0 5.0 7.0 7.0 4.0 7.0 7.0 7.0 0.0 1.0 1.0 0.0 6.0 3.0 9.0 4.0 0.0 5.0 1992.0 W 3.0 2.0 0.0 0.0 3.0 6.0 4.0 3.0 5.0 3.0 5.0 2.0 5.0 867.0 3.0 3.0 1.0 0.0 5.0 5.0 4.0 6.0 3.0 False False False False True False False False False True False False False False False False False False False False False False False True True False False False False False False False False False False True False False False False False True False False False False False False False False True False False False False True False False False True False False False False False True False False True False False False False False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False 80 True False False False True 1 3
In [ ]:
# Do whatever you need to in order to ensure that the dataframe only contains
# the columns that should be passed to the algorithm functions.

data.columns
Out[ ]:
Index(['ALTERSKATEGORIE_GROB', 'ANREDE_KZ', 'FINANZ_MINIMALIST',
       'FINANZ_SPARER', 'FINANZ_VORSORGER', 'FINANZ_ANLEGER',
       'FINANZ_UNAUFFAELLIGER', 'FINANZ_HAUSBAUER', 'GREEN_AVANTGARDE',
       'HEALTH_TYP',
       ...
       'CAMEO_DEU_2015_9D', 'CAMEO_DEU_2015_9E', 'generation',
       'movement_Avantgarde', 'movement_Mainstream', 'nation_E', 'nation_EW',
       'nation_W', 'tens', 'ones'],
      dtype='object', length=196)

Step 1.3: Create a Cleaning Function¶

Even though you've finished cleaning up the general population demographics data, it's important to look ahead to the future and realize that you'll need to perform the same cleaning steps on the customer demographics data. In this substep, complete the function below to execute the main feature selection, encoding, and re-engineering steps you performed above. Then, when it comes to looking at the customer data in Step 3, you can just run this function on that DataFrame to get the trimmed dataset in a single step.

In [ ]:
def convert_Missing_to_Nans(demographicData,FeatureSummary):
    for attribute , missValue in FeatureSummary[['attribute' ,'missing_or_unknown' ]].values :
            missValue=missValue[1:-1]
            missValue = missValue.split(',')
            for x in  missValue  : 
                try :
                    demographicData[attribute].replace(int(x),np.NAN , inplace=True)  
                except :
                    demographicData[attribute].replace(x ,np.NAN , inplace=True)
    return demographicData


def remove_feature_with_alot_ofNans(demographicData,FeatureSummary,
                                    percentage_threshold=30):
    missingValuepercent=demographicData.isna().sum()/len(demographicData)*100

    outier_columns=missingValuepercent[missingValuepercent>percentage_threshold].index
    #removing outlier from FeatureSummary
    outlierMask=[x not in outier_columns for x in  FeatureSummary['attribute'].values]
    FeatureSummary=FeatureSummary[outlierMask]
    
    #removing outlier from demographicData
    demographicData.drop(outier_columns , axis=1 ,inplace=True)
    return demographicData , FeatureSummary


def Split_data_rows_perNan(demographicData ,threshold=10) : 
    row_missingValue=demographicData.isna().sum(axis=1) 
    little_nans=demographicData[ row_missingValue<threshold]
    alot_nans=demographicData[ row_missingValue>threshold] 
    little_nans=little_nans.fillna(method='ffill').fillna(method='bfill')
    return little_nans



def count_featureTypes(FeatureSummary):
    types=FeatureSummary['type'].unique()
    att_dict={}
    att_count_dict={}
    
    for atr_type in types : 
        vals=FeatureSummary['attribute'].loc[FeatureSummary['type']==atr_type].values
        att_dict[atr_type]=vals
        att_count_dict[atr_type]=len(vals)
    return att_dict , att_count_dict


def encode_mulitlevel_categorialFeatures(data,att_dict)  :
    multi_level_features=[]
    binary_level_features=[]

    catfeatures=att_dict['categorical']

    for att in catfeatures : 
        levels=len(data[att].value_counts() )
        if levels <=2 :
            binary_level_features.append(att)
        else :
            multi_level_features.append(att)
    
    data=pd.get_dummies(data,columns=multi_level_features)
    data.dropna(inplace=True)

    return data

def PRAEGENDE_JUGENDJAHRE_features (x)  :
        PRAEGENDE_JUGENDJAHRE_labels={ 
          1: '40s - war years (Mainstream, E+W)',
          2: '40s - reconstruction years (Avantgarde, E+W)',
          3: '50s - economic miracle (Mainstream, E+W)',
          4: '50s - milk bar / Individualisation (Avantgarde, E+W)',
          5: '60s - economic miracle (Mainstream, E+W)',
          6: '60s - generation 68 / student protestors (Avantgarde, W)',
          7: '60s - opponents to the building of the Wall (Avantgarde, E)',
          8: '70s - family orientation (Mainstream, E+W)',
          9: '70s - peace movement (Avantgarde, E+W)',
         10: '80s - Generation Golf (Mainstream, W)',
         11: '80s - ecological awareness (Avantgarde, W)',
         12: '80s - FDJ / communist party youth organisation (Mainstream, E)',
         13: '80s - Swords into ploughshares (Avantgarde, E)',
         14: '90s - digital media kids (Mainstream, E+W)',
         15: '90s - ecological awareness (Avantgarde, E+W)'}
        
        Extractedfeatures=PRAEGENDE_JUGENDJAHRE_labels[x]
        generation=Extractedfeatures[:2]
        movement='Mainstream' if 'Mainstream' in Extractedfeatures else 'Avantgarde' 
        
        if  ' E)' in Extractedfeatures : 
            nation='E'
        elif ' W)' in Extractedfeatures : 
            nation='W'
        elif ' E+W)' in Extractedfeatures : 
            nation='EW'
    
        return [generation , movement ,nation]

def features_PRAEGENDE_postProcess(data) :
    features_PRAEGENDE=data['PRAEGENDE_JUGENDJAHRE'].apply(PRAEGENDE_JUGENDJAHRE_features)
    features_PRAEGENDE=pd.DataFrame(list(features_PRAEGENDE),columns=['generation' , 'movement' ,'nation']) 
    features_PRAEGENDE=pd.get_dummies(features_PRAEGENDE, columns=[ 'movement' ,'nation'])
    
    return features_PRAEGENDE

def CAMEO_INTL_featrues(data) :

    CAMEO_INTL=list(data["CAMEO_INTL_2015"].astype('str').apply(lambda x : [x[0],x[1]]) )
    CAMEO_INTL_df=pd.DataFrame(CAMEO_INTL,columns=['tens','ones'])

        
    return CAMEO_INTL_df


def clean_data(demographicData,FeatureSummary,percentage_threshold=30,use_columns=None):
    """
    Perform feature trimming, re-encoding, and engineering for demographics
    data
    
    INPUT: Demographics DataFrame
    OUTPUT: Trimmed and cleaned demographics DataFrame
    """
    
    
    # Put in code here to execute all main cleaning steps:
    # convert missing value codes into NaNs, ...
    demographicData=convert_Missing_to_Nans(demographicData,FeatureSummary )
    
    # remove selected columns and rows, ...
    if type(use_columns)==type(None) :
        demographicData , FeatureSummary = remove_feature_with_alot_ofNans(demographicData,FeatureSummary,
                                        percentage_threshold=percentage_threshold)
    else : 
        demographicData=demographicData[use_columns]
        FeatureSummary=FeatureSummary.loc[[x in use_columns for x in FeatureSummary['attribute']  ] ]

    
    demographicData.dropna(inplace=True)
     
    #data = Split_data_rows_perNan(demographicData ,threshold=10)
    
    
    att_dict , att_count_dict = count_featureTypes(FeatureSummary)
    
    
    data=encode_mulitlevel_categorialFeatures(demographicData,att_dict)
    # select, re-encode, and engineer column values.
 

    #feature engineering for PRAEGENDE_JUGENDJAHRE
    features_PRAEGENDE=features_PRAEGENDE_postProcess(data)
 
    #feature  engineering for CAMEO_INTL
    CAMEO_INTL_df=CAMEO_INTL_featrues(data)
 
    
    data=pd.concat([data,features_PRAEGENDE,CAMEO_INTL_df],axis=1) 
 
    
    data.drop(att_dict['mixed'],axis=1 , inplace=True)

    return data , demographicData.columns
In [ ]:
# Load in the general demographics data.
demographicData=pd.read_csv('Udacity_AZDIAS_Subset.csv',sep=';' )

demographicData.drop(['GEBAEUDETYP'],axis=1,inplace=True)
# Load in the feature summary file.
FeatureSummary=pd.read_csv('AZDIAS_Feature_Summary.csv',sep=';' )
 
FeatureSummary.drop( FeatureSummary[FeatureSummary['attribute'] == 'GEBAEUDETYP'].index ,inplace=True )

data,input_features=clean_data(demographicData,FeatureSummary)
data.head()
Out[ ]:
ALTERSKATEGORIE_GROB ANREDE_KZ FINANZ_MINIMALIST FINANZ_SPARER FINANZ_VORSORGER FINANZ_ANLEGER FINANZ_UNAUFFAELLIGER FINANZ_HAUSBAUER GREEN_AVANTGARDE HEALTH_TYP RETOURTYP_BK_S SEMIO_SOZ SEMIO_FAM SEMIO_REL SEMIO_MAT SEMIO_VERT SEMIO_LUST SEMIO_ERL SEMIO_KULT SEMIO_RAT SEMIO_KRIT SEMIO_DOM SEMIO_KAEM SEMIO_PFLICHT SEMIO_TRADV SOHO_KZ VERS_TYP ANZ_PERSONEN ANZ_TITEL HH_EINKOMMEN_SCORE W_KEIT_KIND_HH WOHNDAUER_2008 ANZ_HAUSHALTE_AKTIV ANZ_HH_TITEL KONSUMNAEHE MIN_GEBAEUDEJAHR OST_WEST_KZ KBA05_ANTG1 KBA05_ANTG2 KBA05_ANTG3 KBA05_ANTG4 KBA05_GBZ BALLRAUM EWDICHTE INNENSTADT GEBAEUDETYP_RASTER KKK MOBI_REGIO ONLINE_AFFINITAET REGIOTYP KBA13_ANZAHL_PKW PLZ8_ANTG1 PLZ8_ANTG2 PLZ8_ANTG3 PLZ8_ANTG4 PLZ8_HHZ PLZ8_GBZ ARBEIT ORTSGR_KLS9 RELAT_AB CJT_GESAMTTYP_1.0 CJT_GESAMTTYP_2.0 CJT_GESAMTTYP_3.0 CJT_GESAMTTYP_4.0 CJT_GESAMTTYP_5.0 CJT_GESAMTTYP_6.0 FINANZTYP_1 FINANZTYP_2 FINANZTYP_3 FINANZTYP_4 FINANZTYP_5 FINANZTYP_6 GFK_URLAUBERTYP_1.0 GFK_URLAUBERTYP_2.0 GFK_URLAUBERTYP_3.0 GFK_URLAUBERTYP_4.0 GFK_URLAUBERTYP_5.0 GFK_URLAUBERTYP_6.0 GFK_URLAUBERTYP_7.0 GFK_URLAUBERTYP_8.0 GFK_URLAUBERTYP_9.0 GFK_URLAUBERTYP_10.0 GFK_URLAUBERTYP_11.0 GFK_URLAUBERTYP_12.0 LP_FAMILIE_FEIN_1.0 LP_FAMILIE_FEIN_2.0 LP_FAMILIE_FEIN_3.0 LP_FAMILIE_FEIN_4.0 LP_FAMILIE_FEIN_5.0 LP_FAMILIE_FEIN_6.0 LP_FAMILIE_FEIN_7.0 LP_FAMILIE_FEIN_8.0 LP_FAMILIE_FEIN_9.0 LP_FAMILIE_FEIN_10.0 LP_FAMILIE_FEIN_11.0 LP_FAMILIE_GROB_1.0 LP_FAMILIE_GROB_2.0 LP_FAMILIE_GROB_3.0 LP_FAMILIE_GROB_4.0 LP_FAMILIE_GROB_5.0 LP_STATUS_FEIN_1.0 LP_STATUS_FEIN_2.0 LP_STATUS_FEIN_3.0 LP_STATUS_FEIN_4.0 LP_STATUS_FEIN_5.0 LP_STATUS_FEIN_6.0 LP_STATUS_FEIN_7.0 LP_STATUS_FEIN_8.0 LP_STATUS_FEIN_9.0 LP_STATUS_FEIN_10.0 LP_STATUS_GROB_1.0 LP_STATUS_GROB_2.0 LP_STATUS_GROB_3.0 LP_STATUS_GROB_4.0 LP_STATUS_GROB_5.0 NATIONALITAET_KZ_1.0 NATIONALITAET_KZ_2.0 NATIONALITAET_KZ_3.0 SHOPPER_TYP_0.0 SHOPPER_TYP_1.0 SHOPPER_TYP_2.0 SHOPPER_TYP_3.0 ZABEOTYP_1 ZABEOTYP_2 ZABEOTYP_3 ZABEOTYP_4 ZABEOTYP_5 ZABEOTYP_6 CAMEO_DEUG_2015_1 CAMEO_DEUG_2015_2 CAMEO_DEUG_2015_3 CAMEO_DEUG_2015_4 CAMEO_DEUG_2015_5 CAMEO_DEUG_2015_6 CAMEO_DEUG_2015_7 CAMEO_DEUG_2015_8 CAMEO_DEUG_2015_9 CAMEO_DEU_2015_1A CAMEO_DEU_2015_1B CAMEO_DEU_2015_1C CAMEO_DEU_2015_1D CAMEO_DEU_2015_1E CAMEO_DEU_2015_2A CAMEO_DEU_2015_2B CAMEO_DEU_2015_2C CAMEO_DEU_2015_2D CAMEO_DEU_2015_3A CAMEO_DEU_2015_3B CAMEO_DEU_2015_3C CAMEO_DEU_2015_3D CAMEO_DEU_2015_4A CAMEO_DEU_2015_4B CAMEO_DEU_2015_4C CAMEO_DEU_2015_4D CAMEO_DEU_2015_4E CAMEO_DEU_2015_5A CAMEO_DEU_2015_5B CAMEO_DEU_2015_5C CAMEO_DEU_2015_5D CAMEO_DEU_2015_5E CAMEO_DEU_2015_5F CAMEO_DEU_2015_6A CAMEO_DEU_2015_6B CAMEO_DEU_2015_6C CAMEO_DEU_2015_6D CAMEO_DEU_2015_6E CAMEO_DEU_2015_6F CAMEO_DEU_2015_7A CAMEO_DEU_2015_7B CAMEO_DEU_2015_7C CAMEO_DEU_2015_7D CAMEO_DEU_2015_7E CAMEO_DEU_2015_8A CAMEO_DEU_2015_8B CAMEO_DEU_2015_8C CAMEO_DEU_2015_8D CAMEO_DEU_2015_9A CAMEO_DEU_2015_9B CAMEO_DEU_2015_9C CAMEO_DEU_2015_9D CAMEO_DEU_2015_9E generation movement_Avantgarde movement_Mainstream nation_E nation_EW nation_W tens ones
1 1.0 2.0 1.0 5.0 2.0 5.0 4.0 5.0 0.0 3.0 1.0 5.0 4.0 4.0 3.0 1.0 2.0 2.0 3.0 6.0 4.0 7.0 4.0 7.0 6.0 1.0 2.0 2.0 0.0 6.0 3.0 9.0 11.0 0.0 1.0 1992.0 W 0.0 0.0 0.0 2.0 1.0 6.0 3.0 8.0 3.0 2.0 1.0 3.0 3.0 963.0 2.0 3.0 2.0 1.0 5.0 4.0 3.0 5.0 4.0 False False False False True False True False False False False False False False False False False False False False False True False False False False False False True False False False False False False False False True False False False True False False False False False False False False True False False False False True False False False False False True False False False False True False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True False False False False False False False False 90 True False False True False 2 4
2 3.0 2.0 1.0 4.0 1.0 2.0 3.0 5.0 1.0 3.0 3.0 4.0 1.0 3.0 3.0 4.0 4.0 6.0 3.0 4.0 7.0 7.0 7.0 3.0 3.0 0.0 1.0 1.0 0.0 4.0 3.0 9.0 10.0 0.0 5.0 1992.0 W 1.0 3.0 1.0 0.0 3.0 2.0 4.0 4.0 4.0 2.0 3.0 2.0 2.0 712.0 3.0 3.0 1.0 0.0 4.0 4.0 3.0 5.0 2.0 False False True False False False True False False False False False False False False False False False False False False True False False True False False False False False False False False False False True False False False False False False True False False False False False False False False True False False False True False False False False True False False False False False True False False False False True False False False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False 70 False True False True False 4 3
4 3.0 1.0 4.0 3.0 4.0 1.0 3.0 2.0 0.0 3.0 5.0 6.0 4.0 4.0 2.0 7.0 4.0 4.0 6.0 2.0 3.0 2.0 2.0 4.0 2.0 0.0 2.0 4.0 0.0 5.0 2.0 9.0 3.0 0.0 4.0 1992.0 W 1.0 4.0 1.0 0.0 3.0 2.0 5.0 1.0 5.0 3.0 3.0 5.0 5.0 435.0 2.0 4.0 2.0 1.0 3.0 3.0 4.0 6.0 5.0 False False False False True False False False False False True False False False False False True False False False False False False False False False False False False False False False False True False False False False False True False False True False False False False False False False False True False False False True False False False False True False False False False True False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False 80 False True False False True 2 2
5 1.0 2.0 3.0 1.0 5.0 2.0 2.0 5.0 0.0 3.0 3.0 2.0 4.0 7.0 4.0 2.0 2.0 2.0 5.0 7.0 4.0 4.0 4.0 7.0 6.0 0.0 2.0 1.0 0.0 5.0 6.0 9.0 5.0 0.0 5.0 1992.0 W 2.0 2.0 0.0 0.0 4.0 6.0 2.0 7.0 4.0 4.0 4.0 1.0 5.0 1300.0 2.0 3.0 1.0 1.0 5.0 5.0 2.0 3.0 3.0 False True False False False False False True False False False False True False False False False False False False False False False False True False False False False False False False False False False True False False False False False False False True False False False False False False False True False False False True False False True False False False False False False True False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False True False False False False False False 70 False True False True False 1 4
6 2.0 2.0 1.0 5.0 1.0 5.0 4.0 3.0 0.0 2.0 4.0 2.0 5.0 5.0 7.0 2.0 6.0 5.0 5.0 7.0 7.0 4.0 7.0 7.0 7.0 0.0 1.0 1.0 0.0 6.0 3.0 9.0 4.0 0.0 5.0 1992.0 W 3.0 2.0 0.0 0.0 3.0 6.0 4.0 3.0 5.0 3.0 5.0 2.0 5.0 867.0 3.0 3.0 1.0 0.0 5.0 5.0 4.0 6.0 3.0 False False False False True False False False False True False False False False False False False False False False False False False True True False False False False False False False False False False True False False False False False True False False False False False False False False True False False False False True False False False True False False False False False True False False False False False True False False False False False False False False False False False False False False False False False False True False False False False False False False False False False False False False False False False False False False False False False False False False False False False False False 80 True False False False True 1 3
In [ ]:
input_features
Out[ ]:
Index(['ALTERSKATEGORIE_GROB', 'ANREDE_KZ', 'CJT_GESAMTTYP',
       'FINANZ_MINIMALIST', 'FINANZ_SPARER', 'FINANZ_VORSORGER',
       'FINANZ_ANLEGER', 'FINANZ_UNAUFFAELLIGER', 'FINANZ_HAUSBAUER',
       'FINANZTYP', 'GFK_URLAUBERTYP', 'GREEN_AVANTGARDE', 'HEALTH_TYP',
       'LP_LEBENSPHASE_FEIN', 'LP_LEBENSPHASE_GROB', 'LP_FAMILIE_FEIN',
       'LP_FAMILIE_GROB', 'LP_STATUS_FEIN', 'LP_STATUS_GROB',
       'NATIONALITAET_KZ', 'PRAEGENDE_JUGENDJAHRE', 'RETOURTYP_BK_S',
       'SEMIO_SOZ', 'SEMIO_FAM', 'SEMIO_REL', 'SEMIO_MAT', 'SEMIO_VERT',
       'SEMIO_LUST', 'SEMIO_ERL', 'SEMIO_KULT', 'SEMIO_RAT', 'SEMIO_KRIT',
       'SEMIO_DOM', 'SEMIO_KAEM', 'SEMIO_PFLICHT', 'SEMIO_TRADV',
       'SHOPPER_TYP', 'SOHO_KZ', 'VERS_TYP', 'ZABEOTYP', 'ANZ_PERSONEN',
       'ANZ_TITEL', 'HH_EINKOMMEN_SCORE', 'W_KEIT_KIND_HH', 'WOHNDAUER_2008',
       'ANZ_HAUSHALTE_AKTIV', 'ANZ_HH_TITEL', 'KONSUMNAEHE',
       'MIN_GEBAEUDEJAHR', 'OST_WEST_KZ', 'WOHNLAGE', 'CAMEO_DEUG_2015',
       'CAMEO_DEU_2015', 'CAMEO_INTL_2015', 'KBA05_ANTG1', 'KBA05_ANTG2',
       'KBA05_ANTG3', 'KBA05_ANTG4', 'KBA05_GBZ', 'BALLRAUM', 'EWDICHTE',
       'INNENSTADT', 'GEBAEUDETYP_RASTER', 'KKK', 'MOBI_REGIO',
       'ONLINE_AFFINITAET', 'REGIOTYP', 'KBA13_ANZAHL_PKW', 'PLZ8_ANTG1',
       'PLZ8_ANTG2', 'PLZ8_ANTG3', 'PLZ8_ANTG4', 'PLZ8_BAUMAX', 'PLZ8_HHZ',
       'PLZ8_GBZ', 'ARBEIT', 'ORTSGR_KLS9', 'RELAT_AB'],
      dtype='object')

Step 2: Feature Transformation¶

Step 2.1: Apply Feature Scaling¶

Before we apply dimensionality reduction techniques to the data, we need to perform feature scaling so that the principal component vectors are not influenced by the natural differences in scale for features. Starting from this part of the project, you'll want to keep an eye on the API reference page for sklearn to help you navigate to all of the classes and functions that you'll need. In this substep, you'll need to check the following:

  • sklearn requires that data not have missing values in order for its estimators to work properly. So, before applying the scaler to your data, make sure that you've cleaned the DataFrame of the remaining missing values. This can be as simple as just removing all data points with missing data, or applying an SimpleImputer to replace all missing values. You might also try a more complicated procedure where you temporarily remove missing values in order to compute the scaling parameters before re-introducing those missing values and applying imputation. Think about how much missing data you have and what possible effects each approach might have on your analysis, and justify your decision in the discussion section below.
  • For the actual scaling function, a StandardScaler instance is suggested, scaling each feature to mean 0 and standard deviation 1.
  • For these classes, you can make use of the .fit_transform() method to both fit a procedure to the data as well as apply the transformation to the data at the same time. Don't forget to keep the fit sklearn objects handy, since you'll be applying them to the customer demographics data towards the end of the project.
In [ ]:
# If you've not yet cleaned the dataset of all NaN values, then investigate and
# do that now.

data.dropna(inplace=True)
data=data.apply(lambda X : pd.to_numeric(X, errors='coerce').fillna(0).astype(float)) 
data.dropna(inplace=True)
generalPopulatio=data.copy()
In [ ]:
# Apply feature scaling to the general population demographics data.
scalar=StandardScaler()
scalar.fit(data)
data[data.columns]=scalar.transform(data)
import joblib
joblib.dump(scalar,'scalar.pickle')
 
Out[ ]:
['scalar.pickle']

Discussion 2.1: Apply Feature Scaling¶

two opetion for scaling :

  • MinMaxScalar used when:
    • Range-Sensitive Algorithms: When using algorithms that are sensitive to the scale of the data, such as neural networks and k-nearest neighbors. These algorithms perform better when data is within a bounded range.
    • Preservation of Zero Value: When you need to preserve the zero values in the data and the relationship between the original data points.
    • Bounded Data: When you know the data is already within a fixed range (e.g., image data with pixel values between 0 and 255).
    • Robustness to Outliers: When the data contains outliers that should influence the scaling process, because MinMaxScaler considers the minimum and maximum values which can be significantly affected by outliers.
  • StandardScalar used when:

    • Assumption of Normal Distribution: When the algorithm assumes or performs better if the features are normally distributed (e.g., linear regression, logistic regression, support vector machines, principal component analysis (PCA)).

    • Standardized Data Requirement: When the algorithm requires data to be standardized rather than just normalized (e.g., algorithms that rely on distance measurements in multi-dimensional space).

    • Outliers: When you want to reduce the effect of outliers. Since the mean and standard deviation are less influenced by outliers than the minimum and maximum values, StandardScaler is more robust to outliers compared to MinMaxScaler.

Since we are worknig with dimenstionality reduction (PCA ) then we will use StandardScalar

Step 2.2: Perform Dimensionality Reduction¶

On your scaled data, you are now ready to apply dimensionality reduction techniques.

  • Use sklearn's PCA class to apply principal component analysis on the data, thus finding the vectors of maximal variance in the data. To start, you should not set any parameters (so all components are computed) or set a number of components that is at least half the number of features (so there's enough features to see the general trend in variability).
  • Check out the ratio of variance explained by each principal component as well as the cumulative variance explained. Try plotting the cumulative or sequential values using matplotlib's plot() function. Based on what you find, select a value for the number of transformed features you'll retain for the clustering part of the project.
  • Once you've made a choice for the number of components to keep, make sure you re-fit a PCA instance to perform the decided-on transformation.
In [ ]:
# Apply PCA to the data.

from sklearn.decomposition import PCA

component=180
pca = PCA(n_components=component)

Data_pca=pca.fit_transform(data)
varianceRatio=pca.explained_variance_ratio_ 
In [ ]:
# Investigate the variance accounted for by each principal component.

f,axs = plt.subplots(2, sharex=True,figsize=(10,10))
 
axs[0].set_title('Variance')


axs[0].bar(x=range(component) ,height=varianceRatio)
axs[1].scatter(x=range(component) ,y=pd.Series(varianceRatio.cumsum()))

axs[0].set_ylabel('Variance Ratio')
axs[1].set_ylabel('cumulative sum of the Variance Ratio')
axs[0].set_xlabel('p-component')
plt.show()
In [ ]:
# Re-apply PCA to the data while selecting for number of components to retain.
from sklearn.decomposition import PCA
component=130
pca = PCA(n_components=component)

Data_pca=pca.fit_transform(data)
varianceRatio=pca.explained_variance_ratio_ 

Discussion 2.2: Perform Dimensionality Reduction¶

(Double-click this cell and replace this text with your own text, reporting your findings and decisions regarding dimensionality reduction. How many principal components / transformed features are you retaining for the next step of the analysis?)

the variance described by the principle compenent reachs 90% with almost 130 component which means 90% of the data is represented by 130 component which make it the optimum value

Step 2.3: Interpret Principal Components¶

Now that we have our transformed principal components, it's a nice idea to check out the weight of each variable on the first few components to see if they can be interpreted in some fashion.

As a reminder, each principal component is a unit vector that points in the direction of highest variance (after accounting for the variance captured by earlier principal components). The further a weight is from zero, the more the principal component is in the direction of the corresponding feature. If two features have large weights of the same sign (both positive or both negative), then increases in one tend expect to be associated with increases in the other. To contrast, features with different signs can be expected to show a negative correlation: increases in one variable should result in a decrease in the other.

  • To investigate the features, you should map each weight to their corresponding feature name, then sort the features according to weight. The most interesting features for each principal component, then, will be those at the beginning and end of the sorted list. Use the data dictionary document to help you understand these most prominent features, their relationships, and what a positive or negative value on the principal component might indicate.
  • You should investigate and interpret feature associations from the first three principal components in this substep. To help facilitate this, you should write a function that you can call at any time to print the sorted list of feature weights, for the i-th principal component. This might come in handy in the next step of the project, when you interpret the tendencies of the discovered clusters.
In [ ]:
# Map weights for the first principal component to corresponding feature names
# and then print the linked values, sorted by weight.
# HINT: Try defining a function here or in a new cell that you can reuse in the
# other cells.

def Component_Weights(pca,component_number,number_of_features=10,plot=False) :

    i=component_number
    comp_wieghts=pd.DataFrame( pca.components_ , columns=pca.feature_names_in_)

    wieghts=comp_wieghts.iloc[i].sort_values(ascending=False,key=lambda x: abs(x))

    wieghts=wieghts.iloc[:number_of_features]
    if plot :
        plt.rcParams["figure.figsize"] = (18, 10)
        plt.Figure()
        plt.bar(x=wieghts.index ,height=wieghts.values)
        plt.ylabel('wieght')
        plt.title(f'Weights of the features for {i} component')
        plt.show()
    return wieghts

Component_Weights(pca,0,number_of_features=120,plot=True)
Out[ ]:
MOBI_REGIO              -0.210659
FINANZ_MINIMALIST       -0.203511
LP_STATUS_GROB_1.0       0.201107
KBA05_ANTG1             -0.197871
KBA05_GBZ               -0.187472
PLZ8_ANTG1              -0.186344
PLZ8_ANTG3               0.185785
HH_EINKOMMEN_SCORE       0.184046
PLZ8_ANTG4               0.178935
ORTSGR_KLS9              0.159325
EWDICHTE                 0.157399
FINANZ_HAUSBAUER         0.142899
PLZ8_GBZ                -0.137776
KONSUMNAEHE             -0.135507
FINANZ_SPARER            0.134426
INNENSTADT              -0.131613
LP_STATUS_FEIN_1.0       0.130385
KBA05_ANTG4              0.129181
PLZ8_ANTG2               0.125905
FINANZTYP_1              0.124027
LP_STATUS_FEIN_10.0     -0.121720
LP_STATUS_GROB_5.0      -0.121720
KBA05_ANTG3              0.121028
LP_STATUS_FEIN_2.0       0.120242
ARBEIT                   0.117653
ANZ_HAUSHALTE_AKTIV      0.116938
LP_STATUS_GROB_4.0      -0.112659
ALTERSKATEGORIE_GROB    -0.111859
LP_STATUS_FEIN_9.0      -0.111823
CAMEO_DEUG_2015_9        0.111764
RELAT_AB                 0.108992
GREEN_AVANTGARDE        -0.107787
FINANZ_VORSORGER        -0.103973
SEMIO_PFLICHT            0.101430
BALLRAUM                -0.099330
SEMIO_REL                0.095243
GEBAEUDETYP_RASTER      -0.094434
ZABEOTYP_1              -0.093650
LP_FAMILIE_GROB_1.0      0.091400
LP_FAMILIE_FEIN_1.0      0.091400
CAMEO_DEUG_2015_8        0.090643
SEMIO_TRADV              0.090560
ANZ_PERSONEN            -0.089620
FINANZTYP_2             -0.088358
ZABEOTYP_5               0.087200
SEMIO_RAT                0.087084
CAMEO_DEUG_2015_2       -0.083820
SEMIO_LUST              -0.082169
CAMEO_DEUG_2015_4       -0.074044
SEMIO_MAT                0.073978
SEMIO_ERL               -0.072595
FINANZ_UNAUFFAELLIGER    0.072178
LP_FAMILIE_GROB_5.0     -0.070665
FINANZ_ANLEGER           0.068000
NATIONALITAET_KZ_1.0    -0.067667
GFK_URLAUBERTYP_12.0     0.066436
SEMIO_FAM                0.066078
KBA13_ANZAHL_PKW        -0.064429
REGIOTYP                 0.063939
WOHNDAUER_2008          -0.063904
CAMEO_DEUG_2015_3       -0.063508
CAMEO_DEU_2015_8A        0.061257
SEMIO_KULT               0.061102
CAMEO_DEU_2015_9C        0.057270
NATIONALITAET_KZ_2.0     0.056990
CAMEO_DEU_2015_9B        0.056775
CAMEO_DEU_2015_9D        0.056062
CJT_GESAMTTYP_2.0       -0.054059
LP_FAMILIE_FEIN_11.0    -0.049301
CAMEO_DEU_2015_2D       -0.048237
LP_FAMILIE_FEIN_10.0    -0.047594
CAMEO_DEUG_2015_1       -0.046844
CAMEO_DEU_2015_4C       -0.046649
CAMEO_DEU_2015_4A       -0.046501
GFK_URLAUBERTYP_7.0     -0.046238
CAMEO_DEU_2015_2C       -0.044604
FINANZTYP_3             -0.044191
ZABEOTYP_4               0.043758
SHOPPER_TYP_2.0          0.041870
ZABEOTYP_6               0.041602
ZABEOTYP_2              -0.041441
CAMEO_DEU_2015_8B        0.041005
KKK                      0.040636
CAMEO_DEU_2015_3D       -0.040591
ONLINE_AFFINITAET       -0.039509
CAMEO_DEU_2015_9A        0.038446
SHOPPER_TYP_3.0         -0.038443
CAMEO_DEU_2015_1D       -0.038311
W_KEIT_KIND_HH           0.037746
CAMEO_DEU_2015_2B       -0.037115
FINANZTYP_6             -0.035935
CAMEO_DEU_2015_3C       -0.035348
LP_FAMILIE_FEIN_2.0     -0.035233
LP_FAMILIE_GROB_2.0     -0.035233
ZABEOTYP_3              -0.034954
SEMIO_KAEM               0.034848
CAMEO_DEU_2015_8C        0.034406
SEMIO_VERT              -0.033933
PLZ8_HHZ                 0.033646
NATIONALITAET_KZ_3.0     0.033019
MIN_GEBAEUDEJAHR        -0.032349
SEMIO_SOZ                0.032036
LP_STATUS_GROB_3.0      -0.031982
GFK_URLAUBERTYP_6.0     -0.031724
HEALTH_TYP               0.031468
CAMEO_DEU_2015_2A       -0.030924
CAMEO_DEUG_2015_7        0.029168
LP_STATUS_FEIN_6.0      -0.028339
GFK_URLAUBERTYP_11.0     0.028319
GFK_URLAUBERTYP_5.0     -0.027890
CJT_GESAMTTYP_4.0        0.027117
ANZ_HH_TITEL             0.026177
RETOURTYP_BK_S          -0.025262
CAMEO_DEU_2015_8D        0.025186
CJT_GESAMTTYP_3.0        0.024554
CAMEO_DEU_2015_7B        0.024362
CAMEO_DEU_2015_3B       -0.024018
LP_FAMILIE_FEIN_8.0     -0.023289
LP_STATUS_FEIN_4.0      -0.023169
LP_FAMILIE_GROB_4.0     -0.022279
Name: 0, dtype: float64
In [ ]:
# Map weights for the second principal component to corresponding feature names
# and then print the linked values, sorted by weight.

Component_Weights(pca,1,number_of_features=200,plot=True)
Out[ ]:
ALTERSKATEGORIE_GROB     0.233692
SEMIO_REL               -0.227598
FINANZ_SPARER           -0.216412
SEMIO_PFLICHT           -0.213837
SEMIO_TRADV             -0.210374
FINANZ_VORSORGER         0.208838
FINANZ_UNAUFFAELLIGER   -0.208554
ZABEOTYP_3               0.205123
FINANZ_ANLEGER          -0.195962
SEMIO_ERL                0.194630
SEMIO_KULT              -0.178389
ONLINE_AFFINITAET       -0.166401
SEMIO_RAT               -0.163560
SEMIO_LUST               0.160976
RETOURTYP_BK_S           0.159031
SEMIO_FAM               -0.141751
W_KEIT_KIND_HH           0.131186
SEMIO_MAT               -0.127953
FINANZTYP_1             -0.120696
ZABEOTYP_4              -0.109900
LP_STATUS_FEIN_1.0       0.109087
CJT_GESAMTTYP_2.0        0.103086
FINANZ_HAUSBAUER         0.098271
SEMIO_KRIT               0.094795
FINANZTYP_5              0.092437
FINANZTYP_4             -0.092073
LP_STATUS_FEIN_2.0      -0.089181
PLZ8_ANTG3               0.084504
MOBI_REGIO              -0.083916
PLZ8_ANTG1              -0.083248
LP_STATUS_FEIN_5.0      -0.082278
KBA05_GBZ               -0.081705
ZABEOTYP_5              -0.081240
EWDICHTE                 0.080678
PLZ8_ANTG4               0.079862
FINANZTYP_2              0.079674
ORTSGR_KLS9              0.079628
ANZ_PERSONEN            -0.078711
SHOPPER_TYP_3.0          0.077971
KBA05_ANTG1             -0.077248
FINANZTYP_3             -0.077216
ZABEOTYP_1              -0.077005
SEMIO_KAEM               0.075661
LP_FAMILIE_FEIN_1.0      0.075302
LP_FAMILIE_GROB_1.0      0.075302
GFK_URLAUBERTYP_9.0     -0.074784
SEMIO_SOZ               -0.073533
LP_FAMILIE_GROB_4.0     -0.070605
CJT_GESAMTTYP_1.0        0.067614
SHOPPER_TYP_0.0         -0.066219
FINANZ_MINIMALIST        0.065649
INNENSTADT              -0.065263
NATIONALITAET_KZ_1.0     0.064978
PLZ8_GBZ                -0.064052
FINANZTYP_6              0.063995
KONSUMNAEHE             -0.060531
KBA05_ANTG4              0.060220
ARBEIT                   0.059820
GFK_URLAUBERTYP_4.0      0.058547
PLZ8_ANTG2               0.057940
RELAT_AB                 0.056612
LP_FAMILIE_GROB_5.0     -0.056336
ANREDE_KZ                0.054537
ANZ_HAUSHALTE_AKTIV      0.054206
CJT_GESAMTTYP_4.0       -0.054069
BALLRAUM                -0.051568
LP_STATUS_FEIN_3.0       0.051039
WOHNDAUER_2008           0.048974
NATIONALITAET_KZ_3.0    -0.047634
HH_EINKOMMEN_SCORE       0.047384
LP_FAMILIE_GROB_3.0     -0.046985
CAMEO_DEUG_2015_8        0.046844
KBA05_ANTG3              0.045342
LP_FAMILIE_FEIN_11.0    -0.044343
HEALTH_TYP              -0.043813
NATIONALITAET_KZ_2.0    -0.043429
LP_FAMILIE_FEIN_7.0     -0.043083
CAMEO_DEUG_2015_4       -0.043001
CJT_GESAMTTYP_6.0       -0.042476
LP_FAMILIE_FEIN_8.0     -0.040998
GFK_URLAUBERTYP_2.0     -0.040618
SEMIO_DOM                0.040325
LP_STATUS_GROB_1.0       0.039136
GEBAEUDETYP_RASTER      -0.038038
CAMEO_DEU_2015_8D        0.037726
SEMIO_VERT              -0.037627
LP_FAMILIE_FEIN_6.0     -0.036898
LP_FAMILIE_FEIN_2.0      0.036610
LP_FAMILIE_GROB_2.0      0.036610
GFK_URLAUBERTYP_12.0    -0.035606
GFK_URLAUBERTYP_7.0      0.034177
CJT_GESAMTTYP_5.0       -0.033774
CAMEO_DEU_2015_9E        0.032651
LP_FAMILIE_FEIN_10.0    -0.032237
CJT_GESAMTTYP_3.0       -0.031896
CAMEO_DEU_2015_4A       -0.031441
KBA13_ANZAHL_PKW        -0.031436
CAMEO_DEUG_2015_2       -0.030491
LP_FAMILIE_FEIN_4.0     -0.029882
GFK_URLAUBERTYP_3.0      0.029511
ZABEOTYP_2              -0.028110
LP_STATUS_GROB_4.0      -0.027621
ANZ_HH_TITEL             0.026647
LP_FAMILIE_FEIN_5.0     -0.026569
ZABEOTYP_6               0.026428
CAMEO_DEU_2015_4C       -0.026396
MIN_GEBAEUDEJAHR        -0.026141
CAMEO_DEU_2015_6E        0.025685
GFK_URLAUBERTYP_1.0     -0.024675
CAMEO_DEUG_2015_3       -0.024621
LP_FAMILIE_FEIN_3.0     -0.024472
CAMEO_DEUG_2015_9        0.023857
LP_STATUS_FEIN_4.0      -0.023383
VERS_TYP                 0.023252
GFK_URLAUBERTYP_5.0      0.022365
LP_STATUS_FEIN_8.0      -0.022071
SHOPPER_TYP_1.0         -0.021837
CAMEO_DEU_2015_8A        0.021613
LP_STATUS_FEIN_9.0      -0.020883
GFK_URLAUBERTYP_8.0      0.020324
REGIOTYP                 0.019817
CAMEO_DEU_2015_8C        0.018978
CAMEO_DEU_2015_3C       -0.018473
GREEN_AVANTGARDE        -0.018373
CAMEO_DEU_2015_2A       -0.017667
CAMEO_DEU_2015_9D        0.017301
CAMEO_DEU_2015_2C       -0.016491
GFK_URLAUBERTYP_6.0      0.015340
CAMEO_DEU_2015_3B       -0.015287
CAMEO_DEU_2015_2B       -0.014976
CAMEO_DEU_2015_5C       -0.014598
CAMEO_DEU_2015_8B        0.014143
LP_STATUS_GROB_2.0      -0.013782
CAMEO_DEU_2015_4B       -0.013775
CAMEO_DEU_2015_2D       -0.013174
CAMEO_DEU_2015_5B       -0.012740
LP_STATUS_FEIN_6.0      -0.012349
PLZ8_HHZ                 0.012229
CAMEO_DEU_2015_3A       -0.012075
CAMEO_DEUG_2015_6        0.011453
CAMEO_DEU_2015_7C        0.011308
CAMEO_DEU_2015_5D        0.011252
CAMEO_DEU_2015_9C        0.011208
CAMEO_DEU_2015_7E        0.011083
CAMEO_DEUG_2015_7        0.010926
LP_FAMILIE_FEIN_9.0     -0.010871
GFK_URLAUBERTYP_11.0    -0.010402
CAMEO_DEU_2015_7B        0.010331
CAMEO_DEU_2015_6F        0.010282
LP_STATUS_FEIN_7.0       0.008733
CAMEO_DEU_2015_7D        0.008472
CAMEO_DEU_2015_6B       -0.007047
CAMEO_DEU_2015_3D       -0.006811
CAMEO_DEU_2015_9B        0.006599
CAMEO_DEUG_2015_5       -0.006473
GFK_URLAUBERTYP_10.0     0.006467
LP_STATUS_GROB_3.0      -0.006394
ANZ_TITEL                0.006260
CAMEO_DEU_2015_6D        0.006072
SHOPPER_TYP_2.0          0.006033
CAMEO_DEU_2015_7A       -0.005932
CAMEO_DEU_2015_1D       -0.005607
CAMEO_DEUG_2015_1       -0.005519
CAMEO_DEU_2015_6C        0.005082
LP_STATUS_GROB_5.0      -0.004883
LP_STATUS_FEIN_10.0     -0.004883
KBA05_ANTG2             -0.004579
CAMEO_DEU_2015_4D       -0.004560
CAMEO_DEU_2015_9A       -0.004527
CAMEO_DEU_2015_1A       -0.003441
CAMEO_DEU_2015_5A       -0.003095
SOHO_KZ                 -0.002306
CAMEO_DEU_2015_5E        0.002144
KKK                      0.001564
CAMEO_DEU_2015_1B       -0.001367
CAMEO_DEU_2015_4E       -0.001314
nation_W                 0.001302
nation_EW               -0.000964
CAMEO_DEU_2015_1C        0.000678
CAMEO_DEU_2015_5F        0.000660
CAMEO_DEU_2015_6A       -0.000585
ones                     0.000522
nation_E                -0.000502
movement_Avantgarde      0.000336
movement_Mainstream     -0.000336
CAMEO_DEU_2015_1E       -0.000256
tens                    -0.000060
generation              -0.000048
OST_WEST_KZ             -0.000000
Name: 1, dtype: float64
In [ ]:
# Map weights for the third principal component to corresponding feature names
# and then print the linked values, sorted by weight.

Component_Weights(pca,2,number_of_features=200,plot=False)
Out[ ]:
ANREDE_KZ               -0.346208
SEMIO_VERT               0.323847
SEMIO_KAEM              -0.317039
SEMIO_DOM               -0.286315
SEMIO_KRIT              -0.259260
SEMIO_FAM                0.255819
SEMIO_SOZ                0.255348
SEMIO_KULT               0.240550
SEMIO_ERL               -0.192569
SEMIO_RAT               -0.169792
FINANZ_ANLEGER          -0.162137
FINANZTYP_5              0.140110
FINANZ_MINIMALIST        0.135192
SHOPPER_TYP_0.0          0.125954
ZABEOTYP_1               0.112722
SEMIO_REL                0.108231
SHOPPER_TYP_2.0         -0.107919
FINANZTYP_1             -0.106438
RETOURTYP_BK_S           0.092315
LP_STATUS_FEIN_2.0      -0.087751
W_KEIT_KIND_HH           0.082111
SEMIO_MAT                0.074099
ZABEOTYP_4              -0.071321
LP_STATUS_FEIN_4.0      -0.071245
FINANZ_SPARER           -0.064353
LP_FAMILIE_GROB_3.0     -0.062502
GREEN_AVANTGARDE         0.061823
EWDICHTE                 0.061169
FINANZ_HAUSBAUER        -0.060584
ORTSGR_KLS9              0.060021
FINANZ_VORSORGER         0.058523
INNENSTADT              -0.053983
FINANZ_UNAUFFAELLIGER   -0.053621
ZABEOTYP_6               0.053522
LP_STATUS_FEIN_1.0       0.050054
SHOPPER_TYP_3.0         -0.048851
PLZ8_ANTG4               0.047662
PLZ8_ANTG3               0.047659
BALLRAUM                -0.047400
KONSUMNAEHE             -0.045985
PLZ8_ANTG1              -0.045906
SHOPPER_TYP_1.0          0.045223
LP_FAMILIE_FEIN_4.0     -0.044475
LP_STATUS_FEIN_10.0      0.043861
LP_STATUS_GROB_5.0       0.043861
LP_STATUS_FEIN_3.0       0.043828
SEMIO_LUST               0.041012
SEMIO_TRADV             -0.038719
GEBAEUDETYP_RASTER      -0.036569
HH_EINKOMMEN_SCORE      -0.036074
ALTERSKATEGORIE_GROB     0.035288
SEMIO_PFLICHT           -0.034927
PLZ8_ANTG2               0.034219
KKK                     -0.034166
PLZ8_GBZ                -0.034004
ONLINE_AFFINITAET       -0.033935
RELAT_AB                 0.033769
NATIONALITAET_KZ_3.0    -0.033713
GFK_URLAUBERTYP_9.0     -0.033426
LP_FAMILIE_FEIN_5.0     -0.032591
GFK_URLAUBERTYP_4.0      0.032176
ARBEIT                   0.032113
LP_FAMILIE_FEIN_2.0      0.030205
LP_FAMILIE_GROB_2.0      0.030205
ZABEOTYP_5              -0.029897
LP_STATUS_GROB_2.0      -0.029783
LP_FAMILIE_FEIN_3.0     -0.029445
CAMEO_DEUG_2015_4       -0.028705
MOBI_REGIO              -0.028189
CJT_GESAMTTYP_6.0       -0.028093
LP_STATUS_GROB_3.0       0.027832
KBA05_ANTG4              0.026926
LP_STATUS_FEIN_5.0      -0.025936
NATIONALITAET_KZ_2.0     0.025581
CAMEO_DEU_2015_9C        0.025055
CJT_GESAMTTYP_2.0       -0.024974
ANZ_HAUSHALTE_AKTIV      0.024440
KBA05_GBZ               -0.024291
CAMEO_DEUG_2015_9        0.023819
ZABEOTYP_3              -0.023336
LP_STATUS_FEIN_7.0       0.022786
WOHNDAUER_2008           0.022753
FINANZTYP_2             -0.021998
LP_FAMILIE_GROB_4.0     -0.021909
CAMEO_DEU_2015_4C       -0.020539
ZABEOTYP_2              -0.020194
CJT_GESAMTTYP_1.0        0.019508
KBA13_ANZAHL_PKW        -0.019489
KBA05_ANTG1             -0.019376
GFK_URLAUBERTYP_12.0    -0.019175
VERS_TYP                 0.019076
CAMEO_DEU_2015_4A       -0.018878
LP_STATUS_FEIN_6.0       0.018682
FINANZTYP_3              0.018015
REGIOTYP                -0.017703
LP_FAMILIE_FEIN_7.0     -0.017624
CAMEO_DEU_2015_8B        0.016757
GFK_URLAUBERTYP_2.0     -0.016727
CAMEO_DEUG_2015_1        0.016241
CAMEO_DEU_2015_5D        0.014632
LP_FAMILIE_GROB_1.0      0.014362
LP_FAMILIE_FEIN_1.0      0.014362
ANZ_HH_TITEL             0.014339
LP_FAMILIE_FEIN_6.0     -0.014282
LP_STATUS_GROB_1.0      -0.013905
CJT_GESAMTTYP_3.0        0.013549
CAMEO_DEUG_2015_3       -0.013171
PLZ8_HHZ                 0.012844
ANZ_TITEL                0.012520
MIN_GEBAEUDEJAHR        -0.012341
CAMEO_DEUG_2015_8        0.012185
CAMEO_DEU_2015_1D        0.011852
CAMEO_DEU_2015_9D        0.011832
CAMEO_DEU_2015_9B        0.011201
CAMEO_DEU_2015_1E        0.011042
CAMEO_DEU_2015_5C       -0.010767
CAMEO_DEU_2015_7A       -0.010514
CJT_GESAMTTYP_5.0        0.010492
KBA05_ANTG2             -0.009719
GFK_URLAUBERTYP_6.0      0.009653
CAMEO_DEU_2015_6B       -0.009517
CAMEO_DEU_2015_4B       -0.008905
GFK_URLAUBERTYP_5.0      0.008648
CJT_GESAMTTYP_4.0        0.008605
CAMEO_DEU_2015_3C       -0.007868
CAMEO_DEU_2015_3B       -0.007572
GFK_URLAUBERTYP_8.0      0.007552
CAMEO_DEU_2015_5B       -0.007223
LP_FAMILIE_FEIN_8.0     -0.007091
LP_STATUS_GROB_4.0      -0.006986
CAMEO_DEU_2015_8A        0.006977
CAMEO_DEU_2015_3D       -0.006644
FINANZTYP_4              0.006281
CAMEO_DEUG_2015_6       -0.006264
GFK_URLAUBERTYP_7.0      0.005975
CAMEO_DEU_2015_1C        0.005816
LP_STATUS_FEIN_9.0      -0.005772
CAMEO_DEU_2015_2D        0.005430
GFK_URLAUBERTYP_10.0     0.005033
CAMEO_DEU_2015_8C       -0.004842
CAMEO_DEU_2015_3A       -0.004789
CAMEO_DEU_2015_1A        0.004762
LP_STATUS_FEIN_8.0      -0.004218
CAMEO_DEU_2015_9A       -0.004201
GFK_URLAUBERTYP_11.0    -0.004078
CAMEO_DEU_2015_7B        0.003741
GFK_URLAUBERTYP_3.0      0.003439
CAMEO_DEU_2015_2B       -0.003435
CAMEO_DEU_2015_6E        0.003433
CAMEO_DEU_2015_7C        0.003225
KBA05_ANTG3              0.003186
FINANZTYP_6             -0.003097
CAMEO_DEU_2015_7D        0.002947
CAMEO_DEU_2015_8D        0.002839
CAMEO_DEUG_2015_7       -0.002643
CAMEO_DEU_2015_7E        0.002375
CAMEO_DEU_2015_2C       -0.002347
GFK_URLAUBERTYP_1.0      0.002233
CAMEO_DEU_2015_2A       -0.001856
CAMEO_DEU_2015_6C       -0.001780
CAMEO_DEU_2015_6F        0.001724
LP_FAMILIE_FEIN_11.0    -0.001642
CAMEO_DEU_2015_6A       -0.001453
CAMEO_DEU_2015_5A       -0.001450
LP_FAMILIE_FEIN_9.0     -0.001434
NATIONALITAET_KZ_1.0    -0.001405
CAMEO_DEU_2015_9E        0.001394
LP_FAMILIE_GROB_5.0     -0.001344
CAMEO_DEU_2015_1B        0.001281
movement_Mainstream     -0.001281
movement_Avantgarde      0.001281
CAMEO_DEU_2015_5F        0.001187
CAMEO_DEU_2015_4E       -0.001160
HEALTH_TYP              -0.001048
nation_W                 0.001027
nation_EW               -0.000949
ANZ_PERSONEN            -0.000911
CAMEO_DEU_2015_6D        0.000691
CAMEO_DEU_2015_5E        0.000597
ones                    -0.000563
CAMEO_DEUG_2015_2        0.000465
SOHO_KZ                 -0.000426
generation               0.000388
CAMEO_DEU_2015_4D       -0.000341
tens                    -0.000284
CAMEO_DEUG_2015_5        0.000048
LP_FAMILIE_FEIN_10.0    -0.000020
nation_E                -0.000007
OST_WEST_KZ             -0.000000
Name: 2, dtype: float64

Discussion 2.3: Interpret Principal Components¶

(Double-click this cell and replace this text with your own text, reporting your observations from detailed investigation of the first few principal components generated. Can we interpret positive and negative values from them in a meaningful way?)

Overall Interpretation :

  • Directionality: Positive and negative weights help to understand how different features influence the principal components. Features with positive weights move the component in one direction, while features with negative weights move it in the opposite direction.

  • Feature Importance: The magnitude of the weights indicates the importance of each feature in the formation of the principal component. Larger magnitudes mean greater influence.

    • for example component number 0 :
      • MOBI_REGIO -0.212414
      • LP_STATUS_GROB_1.0 0.203386
      • KBA05_ANTG1 -0.197791
      • FINANZ_MINIMALIST -0.197778
      • PLZ8_ANTG3 0.191088
      • PLZ8_ANTG1 -0.190011
      • KBA05_GBZ -0.189756
      • HH_EINKOMMEN_SCORE 0.188676
      • PLZ8_ANTG4 0.184524
      • ORTSGR_KLS9 0.166269
      • EWDICHTE 0.165372
      • FINANZ_HAUSBAUER 0.156475
      • KONSUMNAEHE -0.144304
      • PLZ8_GBZ -0.138068
      • INNENSTADT -0.136942

which means MOBI_REGIO is the most important feature for PC0 and LP_STATUS_GROB_1.0 is the second most important features and so forth

  • Data Structure: By examining which features have high positive or negative weights across different components, you can infer relationships between features and underlying patterns in the data.

MOBI_REGIO has negative correlation/relation with LP_STATUS_GROB_1.0 however MOBI_REGIO has postitive correlation/relation with KBA05_ANTG1

Step 3: Clustering¶

Step 3.1: Apply Clustering to General Population¶

You've assessed and cleaned the demographics data, then scaled and transformed them. Now, it's time to see how the data clusters in the principal components space. In this substep, you will apply k-means clustering to the dataset and use the average within-cluster distances from each point to their assigned cluster's centroid to decide on a number of clusters to keep.

  • Use sklearn's KMeans class to perform k-means clustering on the PCA-transformed data.
  • Then, compute the average difference from each point to its assigned cluster's center. Hint: The KMeans object's .score() method might be useful here, but note that in sklearn, scores tend to be defined so that larger is better. Try applying it to a small, toy dataset, or use an internet search to help your understanding.
  • Perform the above two steps for a number of different cluster counts. You can then see how the average distance decreases with an increasing number of clusters. However, each additional cluster provides a smaller net benefit. Use this fact to select a final number of clusters in which to group the data. Warning: because of the large size of the dataset, it can take a long time for the algorithm to resolve. The more clusters to fit, the longer the algorithm will take. You should test for cluster counts through at least 10 clusters to get the full picture, but you shouldn't need to test for a number of clusters above about 30.
  • Once you've selected a final number of clusters to use, re-fit a KMeans instance to perform the clustering operation. Make sure that you also obtain the cluster assignments for the general demographics data, since you'll be using them in the final Step 3.3.
In [ ]:
# Over a number of different cluster counts...

from sklearn.cluster import KMeans
from sklearn.metrics import pairwise_distances_argmin_min

K_scores=[]
for k in range(1,25) :
    kmeans = KMeans(n_clusters=k, random_state=42).fit(Data_pca)
    score=kmeans.score(Data_pca) 
    K_scores.append([k,score])
In [ ]:
# Investigate the change in within-cluster distance across number of clusters.
# HINT: Use matplotlib's plot function to visualize this relationship.
k=np.array(K_scores)
plt.Figure()
plt.plot(k[:,0],-k[:,1] , 'ro' ,linewidth=10.0)
plt.show()
In [ ]:
# Re-fit the k-means model with the selected number of clusters and obtain
# cluster predictions for the general population demographics data.
from sklearn.cluster import KMeans
optimum_number_clusters=15
kmeans = KMeans(n_clusters=optimum_number_clusters, random_state=42).fit(Data_pca)

predictions=kmeans.predict(Data_pca)
generalPopulatio['customerSegemnt']=predictions

import joblib 

joblib.dump(generalPopulatio,'training_data.pickle')
joblib.dump(kmeans,'kmeans.pickle')
Out[ ]:
['kmeans.pickle']

Discussion 3.1: Apply Clustering to General Population¶

the Optimum number of clusters/ segments is 15 clusters after the 15 clusters the score which the avg distance between the center of the cluster and the point in the cluster is not changing significantly

Step 3.2: Apply All Steps to the Customer Data¶

Now that you have clusters and cluster centers for the general population, it's time to see how the customer data maps on to those clusters. Take care to not confuse this for re-fitting all of the models to the customer data. Instead, you're going to use the fits from the general population to clean, transform, and cluster the customer data. In the last step of the project, you will interpret how the general population fits apply to the customer data.

  • Don't forget when loading in the customers data, that it is semicolon (;) delimited.
  • Apply the same feature wrangling, selection, and engineering steps to the customer demographics using the clean_data() function you created earlier. (You can assume that the customer demographics data has similar meaning behind missing data patterns as the general demographics data.)
  • Use the sklearn objects from the general demographics data, and apply their transformations to the customers data. That is, you should not be using a .fit() or .fit_transform() method to re-fit the old objects, nor should you be creating new sklearn objects! Carry the data through the feature scaling, PCA, and clustering steps, obtaining cluster assignments for all of the data in the customer demographics data.
In [ ]:
# Load in the customer demographics data.
customers = pd.read_csv('Udacity_CUSTOMERS_Subset.csv',sep=';' )
FeatureSummary=pd.read_csv('AZDIAS_Feature_Summary.csv',sep=';' )
 

FeatureSummary.drop( FeatureSummary[FeatureSummary['attribute'] == 'GEBAEUDETYP'].index ,inplace=True )
customers.drop(['GEBAEUDETYP'],axis=1,inplace=True)
 
In [ ]:
# Apply preprocessing, feature transformation, and clustering from the general
# demographics onto the customer data, obtaining cluster predictions for the
# customer demographics data.
scalar=joblib.load('scalar.pickle')
cleaned_data,feature_in=clean_data(customers,FeatureSummary,percentage_threshold=30,use_columns=input_features)

cleaned_data=cleaned_data.apply(lambda X : pd.to_numeric(X, errors='coerce').fillna(0).astype(float)) 
cleaned_data.dropna(inplace=True)

scalarFeatures=scalar.feature_names_in_

scaled_data=pd.DataFrame()
scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )

transformed_data=pca.transform(scaled_data)
predictions=kmeans.predict(transformed_data)

cleaned_data['customerSegemnt']=predictions

joblib.dump(cleaned_data,'cleaned_data.pickle')
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\57844654.py:136: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  demographicData.dropna(inplace=True)
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
C:\Users\yazan\AppData\Local\Temp\ipykernel_22116\3100293462.py:13: PerformanceWarning: DataFrame is highly fragmented.  This is usually the result of calling `frame.insert` many times, which has poor performance.  Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`
  scaled_data[scalarFeatures] =scalar.transform( cleaned_data[scalarFeatures] )
Out[ ]:
['cleaned_data.pickle']

Step 3.3: Compare Customer Data to Demographics Data¶

At this point, you have clustered data based on demographics of the general population of Germany, and seen how the customer data for a mail-order sales company maps onto those demographic clusters. In this final substep, you will compare the two cluster distributions to see where the strongest customer base for the company is.

Consider the proportion of persons in each cluster for the general population, and the proportions for the customers. If we think the company's customer base to be universal, then the cluster assignment proportions should be fairly similar between the two. If there are only particular segments of the population that are interested in the company's products, then we should see a mismatch from one to the other. If there is a higher proportion of persons in a cluster for the customer data compared to the general population (e.g. 5% of persons are assigned to a cluster for the general population, but 15% of the customer data is closest to that cluster's centroid) then that suggests the people in that cluster to be a target audience for the company. On the other hand, the proportion of the data in a cluster being larger in the general population than the customer data (e.g. only 2% of customers closest to a population centroid that captures 6% of the data) suggests that group of persons to be outside of the target demographics.

Take a look at the following points in this step:

  • Compute the proportion of data points in each cluster for the general population and the customer data. Visualizations will be useful here: both for the individual dataset proportions, but also to visualize the ratios in cluster representation between groups. Seaborn's countplot() or barplot() function could be handy.
    • Recall the analysis you performed in step 1.1.3 of the project, where you separated out certain data points from the dataset if they had more than a specified threshold of missing values. If you found that this group was qualitatively different from the main bulk of the data, you should treat this as an additional data cluster in this analysis. Make sure that you account for the number of data points in this subset, for both the general population and customer datasets, when making your computations!
  • Which cluster or clusters are overrepresented in the customer dataset compared to the general population? Select at least one such cluster and infer what kind of people might be represented by that cluster. Use the principal component interpretations from step 2.3 or look at additional components to help you make this inference. Alternatively, you can use the .inverse_transform() method of the PCA and StandardScaler objects to transform centroids back to the original data space and interpret the retrieved values directly.
  • Perform a similar investigation for the underrepresented clusters. Which cluster or clusters are underrepresented in the customer dataset compared to the general population, and what kinds of people are typified by these clusters?
In [ ]:
# Compare the proportion of data in each cluster for the customer data to the
# proportion of data in each cluster for the general population.

display(generalPopulatio.head())
display(cleaned_data.head())
display(generalPopulatio.columns==cleaned_data.columns)
 

training_dataProp=generalPopulatio['customerSegemnt'].value_counts()/len(data)*100 
customer_dataProp= cleaned_data['customerSegemnt'].value_counts()/len(cleaned_data)*100


f, axs = plt.subplots(2,figsize=(10,10))

ax2 = axs[0].twinx()
axs[0].bar(x=training_dataProp.index  , height=training_dataProp.values )
ax2.scatter(x=training_dataProp.index  , y=np.cumsum(training_dataProp.values), c='r',label='cumulative Sum of population' )

ax3 = axs[1].twinx()
axs[1].bar(x=customer_dataProp.index  , height=customer_dataProp.values )
ax3.scatter(x=customer_dataProp.index  , y=np.cumsum(customer_dataProp.values ), c='r' ,label='cumulative Sum of population')

axs[0].set_title('General population')
axs[1].set_title('Customers population')
for ax in axs : 
    ax.set_xticks(range(optimum_number_clusters))
    ax.set_xlabel('Cluster number ')
    ax.set_ylabel('proportion of each cluster (%)')
    ax.grid()
 

ax2.set_ylabel('cumulative Sum of population')
ax3.set_ylabel('cumulative Sum of population')
plt.show()
ALTERSKATEGORIE_GROB ANREDE_KZ FINANZ_MINIMALIST FINANZ_SPARER FINANZ_VORSORGER FINANZ_ANLEGER FINANZ_UNAUFFAELLIGER FINANZ_HAUSBAUER GREEN_AVANTGARDE HEALTH_TYP RETOURTYP_BK_S SEMIO_SOZ SEMIO_FAM SEMIO_REL SEMIO_MAT SEMIO_VERT SEMIO_LUST SEMIO_ERL SEMIO_KULT SEMIO_RAT SEMIO_KRIT SEMIO_DOM SEMIO_KAEM SEMIO_PFLICHT SEMIO_TRADV SOHO_KZ VERS_TYP ANZ_PERSONEN ANZ_TITEL HH_EINKOMMEN_SCORE W_KEIT_KIND_HH WOHNDAUER_2008 ANZ_HAUSHALTE_AKTIV ANZ_HH_TITEL KONSUMNAEHE MIN_GEBAEUDEJAHR OST_WEST_KZ KBA05_ANTG1 KBA05_ANTG2 KBA05_ANTG3 KBA05_ANTG4 KBA05_GBZ BALLRAUM EWDICHTE INNENSTADT GEBAEUDETYP_RASTER KKK MOBI_REGIO ONLINE_AFFINITAET REGIOTYP KBA13_ANZAHL_PKW PLZ8_ANTG1 PLZ8_ANTG2 PLZ8_ANTG3 PLZ8_ANTG4 PLZ8_HHZ PLZ8_GBZ ARBEIT ORTSGR_KLS9 RELAT_AB CJT_GESAMTTYP_1.0 CJT_GESAMTTYP_2.0 CJT_GESAMTTYP_3.0 CJT_GESAMTTYP_4.0 CJT_GESAMTTYP_5.0 CJT_GESAMTTYP_6.0 FINANZTYP_1 FINANZTYP_2 FINANZTYP_3 FINANZTYP_4 FINANZTYP_5 FINANZTYP_6 GFK_URLAUBERTYP_1.0 GFK_URLAUBERTYP_2.0 GFK_URLAUBERTYP_3.0 GFK_URLAUBERTYP_4.0 GFK_URLAUBERTYP_5.0 GFK_URLAUBERTYP_6.0 GFK_URLAUBERTYP_7.0 GFK_URLAUBERTYP_8.0 GFK_URLAUBERTYP_9.0 GFK_URLAUBERTYP_10.0 GFK_URLAUBERTYP_11.0 GFK_URLAUBERTYP_12.0 LP_FAMILIE_FEIN_1.0 LP_FAMILIE_FEIN_2.0 LP_FAMILIE_FEIN_3.0 LP_FAMILIE_FEIN_4.0 LP_FAMILIE_FEIN_5.0 LP_FAMILIE_FEIN_6.0 LP_FAMILIE_FEIN_7.0 LP_FAMILIE_FEIN_8.0 LP_FAMILIE_FEIN_9.0 LP_FAMILIE_FEIN_10.0 LP_FAMILIE_FEIN_11.0 LP_FAMILIE_GROB_1.0 LP_FAMILIE_GROB_2.0 LP_FAMILIE_GROB_3.0 LP_FAMILIE_GROB_4.0 LP_FAMILIE_GROB_5.0 LP_STATUS_FEIN_1.0 LP_STATUS_FEIN_2.0 LP_STATUS_FEIN_3.0 LP_STATUS_FEIN_4.0 LP_STATUS_FEIN_5.0 LP_STATUS_FEIN_6.0 LP_STATUS_FEIN_7.0 LP_STATUS_FEIN_8.0 LP_STATUS_FEIN_9.0 LP_STATUS_FEIN_10.0 LP_STATUS_GROB_1.0 LP_STATUS_GROB_2.0 LP_STATUS_GROB_3.0 LP_STATUS_GROB_4.0 LP_STATUS_GROB_5.0 NATIONALITAET_KZ_1.0 NATIONALITAET_KZ_2.0 NATIONALITAET_KZ_3.0 SHOPPER_TYP_0.0 SHOPPER_TYP_1.0 SHOPPER_TYP_2.0 SHOPPER_TYP_3.0 ZABEOTYP_1 ZABEOTYP_2 ZABEOTYP_3 ZABEOTYP_4 ZABEOTYP_5 ZABEOTYP_6 CAMEO_DEUG_2015_1 CAMEO_DEUG_2015_2 CAMEO_DEUG_2015_3 CAMEO_DEUG_2015_4 CAMEO_DEUG_2015_5 CAMEO_DEUG_2015_6 CAMEO_DEUG_2015_7 CAMEO_DEUG_2015_8 CAMEO_DEUG_2015_9 CAMEO_DEU_2015_1A CAMEO_DEU_2015_1B CAMEO_DEU_2015_1C CAMEO_DEU_2015_1D CAMEO_DEU_2015_1E CAMEO_DEU_2015_2A CAMEO_DEU_2015_2B CAMEO_DEU_2015_2C CAMEO_DEU_2015_2D CAMEO_DEU_2015_3A CAMEO_DEU_2015_3B CAMEO_DEU_2015_3C CAMEO_DEU_2015_3D CAMEO_DEU_2015_4A CAMEO_DEU_2015_4B CAMEO_DEU_2015_4C CAMEO_DEU_2015_4D CAMEO_DEU_2015_4E CAMEO_DEU_2015_5A CAMEO_DEU_2015_5B CAMEO_DEU_2015_5C CAMEO_DEU_2015_5D CAMEO_DEU_2015_5E CAMEO_DEU_2015_5F CAMEO_DEU_2015_6A CAMEO_DEU_2015_6B CAMEO_DEU_2015_6C CAMEO_DEU_2015_6D CAMEO_DEU_2015_6E CAMEO_DEU_2015_6F CAMEO_DEU_2015_7A CAMEO_DEU_2015_7B CAMEO_DEU_2015_7C CAMEO_DEU_2015_7D CAMEO_DEU_2015_7E CAMEO_DEU_2015_8A CAMEO_DEU_2015_8B CAMEO_DEU_2015_8C CAMEO_DEU_2015_8D CAMEO_DEU_2015_9A CAMEO_DEU_2015_9B CAMEO_DEU_2015_9C CAMEO_DEU_2015_9D CAMEO_DEU_2015_9E generation movement_Avantgarde movement_Mainstream nation_E nation_EW nation_W tens ones customerSegemnt
1 1.0 2.0 1.0 5.0 2.0 5.0 4.0 5.0 0.0 3.0 1.0 5.0 4.0 4.0 3.0 1.0 2.0 2.0 3.0 6.0 4.0 7.0 4.0 7.0 6.0 1.0 2.0 2.0 0.0 6.0 3.0 9.0 11.0 0.0 1.0 1992.0 0.0 0.0 0.0 0.0 2.0 1.0 6.0 3.0 8.0 3.0 2.0 1.0 3.0 3.0 963.0 2.0 3.0 2.0 1.0 5.0 4.0 3.0 5.0 4.0 0.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 90.0 1.0 0.0 0.0 1.0 0.0 2.0 4.0 4
2 3.0 2.0 1.0 4.0 1.0 2.0 3.0 5.0 1.0 3.0 3.0 4.0 1.0 3.0 3.0 4.0 4.0 6.0 3.0 4.0 7.0 7.0 7.0 3.0 3.0 0.0 1.0 1.0 0.0 4.0 3.0 9.0 10.0 0.0 5.0 1992.0 0.0 1.0 3.0 1.0 0.0 3.0 2.0 4.0 4.0 4.0 2.0 3.0 2.0 2.0 712.0 3.0 3.0 1.0 0.0 4.0 4.0 3.0 5.0 2.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 70.0 0.0 1.0 0.0 1.0 0.0 4.0 3.0 2
4 3.0 1.0 4.0 3.0 4.0 1.0 3.0 2.0 0.0 3.0 5.0 6.0 4.0 4.0 2.0 7.0 4.0 4.0 6.0 2.0 3.0 2.0 2.0 4.0 2.0 0.0 2.0 4.0 0.0 5.0 2.0 9.0 3.0 0.0 4.0 1992.0 0.0 1.0 4.0 1.0 0.0 3.0 2.0 5.0 1.0 5.0 3.0 3.0 5.0 5.0 435.0 2.0 4.0 2.0 1.0 3.0 3.0 4.0 6.0 5.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 80.0 0.0 1.0 0.0 0.0 1.0 2.0 2.0 2
5 1.0 2.0 3.0 1.0 5.0 2.0 2.0 5.0 0.0 3.0 3.0 2.0 4.0 7.0 4.0 2.0 2.0 2.0 5.0 7.0 4.0 4.0 4.0 7.0 6.0 0.0 2.0 1.0 0.0 5.0 6.0 9.0 5.0 0.0 5.0 1992.0 0.0 2.0 2.0 0.0 0.0 4.0 6.0 2.0 7.0 4.0 4.0 4.0 1.0 5.0 1300.0 2.0 3.0 1.0 1.0 5.0 5.0 2.0 3.0 3.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 70.0 0.0 1.0 0.0 1.0 0.0 1.0 4.0 13
6 2.0 2.0 1.0 5.0 1.0 5.0 4.0 3.0 0.0 2.0 4.0 2.0 5.0 5.0 7.0 2.0 6.0 5.0 5.0 7.0 7.0 4.0 7.0 7.0 7.0 0.0 1.0 1.0 0.0 6.0 3.0 9.0 4.0 0.0 5.0 1992.0 0.0 3.0 2.0 0.0 0.0 3.0 6.0 4.0 3.0 5.0 3.0 5.0 2.0 5.0 867.0 3.0 3.0 1.0 0.0 5.0 5.0 4.0 6.0 3.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 80.0 1.0 0.0 0.0 0.0 1.0 1.0 3.0 10
ALTERSKATEGORIE_GROB ANREDE_KZ FINANZ_MINIMALIST FINANZ_SPARER FINANZ_VORSORGER FINANZ_ANLEGER FINANZ_UNAUFFAELLIGER FINANZ_HAUSBAUER GREEN_AVANTGARDE HEALTH_TYP RETOURTYP_BK_S SEMIO_SOZ SEMIO_FAM SEMIO_REL SEMIO_MAT SEMIO_VERT SEMIO_LUST SEMIO_ERL SEMIO_KULT SEMIO_RAT SEMIO_KRIT SEMIO_DOM SEMIO_KAEM SEMIO_PFLICHT SEMIO_TRADV SOHO_KZ VERS_TYP ANZ_PERSONEN ANZ_TITEL HH_EINKOMMEN_SCORE W_KEIT_KIND_HH WOHNDAUER_2008 ANZ_HAUSHALTE_AKTIV ANZ_HH_TITEL KONSUMNAEHE MIN_GEBAEUDEJAHR OST_WEST_KZ KBA05_ANTG1 KBA05_ANTG2 KBA05_ANTG3 KBA05_ANTG4 KBA05_GBZ BALLRAUM EWDICHTE INNENSTADT GEBAEUDETYP_RASTER KKK MOBI_REGIO ONLINE_AFFINITAET REGIOTYP KBA13_ANZAHL_PKW PLZ8_ANTG1 PLZ8_ANTG2 PLZ8_ANTG3 PLZ8_ANTG4 PLZ8_HHZ PLZ8_GBZ ARBEIT ORTSGR_KLS9 RELAT_AB CJT_GESAMTTYP_1.0 CJT_GESAMTTYP_2.0 CJT_GESAMTTYP_3.0 CJT_GESAMTTYP_4.0 CJT_GESAMTTYP_5.0 CJT_GESAMTTYP_6.0 FINANZTYP_1 FINANZTYP_2 FINANZTYP_3 FINANZTYP_4 FINANZTYP_5 FINANZTYP_6 GFK_URLAUBERTYP_1.0 GFK_URLAUBERTYP_2.0 GFK_URLAUBERTYP_3.0 GFK_URLAUBERTYP_4.0 GFK_URLAUBERTYP_5.0 GFK_URLAUBERTYP_6.0 GFK_URLAUBERTYP_7.0 GFK_URLAUBERTYP_8.0 GFK_URLAUBERTYP_9.0 GFK_URLAUBERTYP_10.0 GFK_URLAUBERTYP_11.0 GFK_URLAUBERTYP_12.0 LP_FAMILIE_FEIN_1.0 LP_FAMILIE_FEIN_2.0 LP_FAMILIE_FEIN_3.0 LP_FAMILIE_FEIN_4.0 LP_FAMILIE_FEIN_5.0 LP_FAMILIE_FEIN_6.0 LP_FAMILIE_FEIN_7.0 LP_FAMILIE_FEIN_8.0 LP_FAMILIE_FEIN_9.0 LP_FAMILIE_FEIN_10.0 LP_FAMILIE_FEIN_11.0 LP_FAMILIE_GROB_1.0 LP_FAMILIE_GROB_2.0 LP_FAMILIE_GROB_3.0 LP_FAMILIE_GROB_4.0 LP_FAMILIE_GROB_5.0 LP_STATUS_FEIN_1.0 LP_STATUS_FEIN_2.0 LP_STATUS_FEIN_3.0 LP_STATUS_FEIN_4.0 LP_STATUS_FEIN_5.0 LP_STATUS_FEIN_6.0 LP_STATUS_FEIN_7.0 LP_STATUS_FEIN_8.0 LP_STATUS_FEIN_9.0 LP_STATUS_FEIN_10.0 LP_STATUS_GROB_1.0 LP_STATUS_GROB_2.0 LP_STATUS_GROB_3.0 LP_STATUS_GROB_4.0 LP_STATUS_GROB_5.0 NATIONALITAET_KZ_1.0 NATIONALITAET_KZ_2.0 NATIONALITAET_KZ_3.0 SHOPPER_TYP_0.0 SHOPPER_TYP_1.0 SHOPPER_TYP_2.0 SHOPPER_TYP_3.0 ZABEOTYP_1 ZABEOTYP_2 ZABEOTYP_3 ZABEOTYP_4 ZABEOTYP_5 ZABEOTYP_6 CAMEO_DEUG_2015_1 CAMEO_DEUG_2015_2 CAMEO_DEUG_2015_3 CAMEO_DEUG_2015_4 CAMEO_DEUG_2015_5 CAMEO_DEUG_2015_6 CAMEO_DEUG_2015_7 CAMEO_DEUG_2015_8 CAMEO_DEUG_2015_9 CAMEO_DEU_2015_1A CAMEO_DEU_2015_1B CAMEO_DEU_2015_1C CAMEO_DEU_2015_1D CAMEO_DEU_2015_1E CAMEO_DEU_2015_2A CAMEO_DEU_2015_2B CAMEO_DEU_2015_2C CAMEO_DEU_2015_2D CAMEO_DEU_2015_3A CAMEO_DEU_2015_3B CAMEO_DEU_2015_3C CAMEO_DEU_2015_3D CAMEO_DEU_2015_4A CAMEO_DEU_2015_4B CAMEO_DEU_2015_4C CAMEO_DEU_2015_4D CAMEO_DEU_2015_4E CAMEO_DEU_2015_5A CAMEO_DEU_2015_5B CAMEO_DEU_2015_5C CAMEO_DEU_2015_5D CAMEO_DEU_2015_5E CAMEO_DEU_2015_5F CAMEO_DEU_2015_6A CAMEO_DEU_2015_6B CAMEO_DEU_2015_6C CAMEO_DEU_2015_6D CAMEO_DEU_2015_6E CAMEO_DEU_2015_6F CAMEO_DEU_2015_7A CAMEO_DEU_2015_7B CAMEO_DEU_2015_7C CAMEO_DEU_2015_7D CAMEO_DEU_2015_7E CAMEO_DEU_2015_8A CAMEO_DEU_2015_8B CAMEO_DEU_2015_8C CAMEO_DEU_2015_8D CAMEO_DEU_2015_9A CAMEO_DEU_2015_9B CAMEO_DEU_2015_9C CAMEO_DEU_2015_9D CAMEO_DEU_2015_9E generation movement_Avantgarde movement_Mainstream nation_E nation_EW nation_W tens ones customerSegemnt
0 4.0 1.0 5.0 1.0 5.0 1.0 2.0 2.0 1.0 1.0 5.0 6.0 5.0 2.0 6.0 6.0 7.0 3.0 4.0 1.0 3.0 1.0 1.0 2.0 1.0 0.0 1.0 2.0 0.0 1.0 6.0 9.0 1.0 0.0 5.0 1992.0 0.0 2.0 2.0 0.0 0.0 4.0 3.0 2.0 4.0 4.0 1.0 4.0 3.0 1.0 1201.0 3.0 3.0 1.0 0.0 5.0 5.0 1.0 2.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 50.0 1.0 0.0 0.0 1.0 0.0 1.0 3.0 8
2 4.0 2.0 5.0 1.0 5.0 1.0 4.0 4.0 1.0 2.0 5.0 2.0 2.0 1.0 3.0 3.0 7.0 7.0 1.0 2.0 7.0 5.0 6.0 4.0 1.0 0.0 2.0 1.0 0.0 1.0 6.0 9.0 1.0 0.0 1.0 1992.0 0.0 2.0 2.0 0.0 0.0 3.0 7.0 4.0 1.0 3.0 3.0 3.0 1.0 7.0 433.0 2.0 3.0 3.0 1.0 3.0 2.0 3.0 5.0 3.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 70.0 0.0 1.0 0.0 1.0 0.0 4.0 1.0 8
4 3.0 1.0 3.0 1.0 4.0 4.0 5.0 2.0 0.0 3.0 5.0 4.0 5.0 4.0 6.0 5.0 6.0 4.0 5.0 5.0 3.0 5.0 2.0 5.0 4.0 0.0 2.0 4.0 0.0 6.0 2.0 9.0 7.0 0.0 1.0 1992.0 0.0 0.0 3.0 2.0 0.0 3.0 3.0 4.0 4.0 3.0 4.0 3.0 5.0 7.0 513.0 2.0 4.0 2.0 1.0 3.0 3.0 3.0 5.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 50.0 1.0 0.0 0.0 1.0 0.0 2.0 3.0 1
5 3.0 1.0 5.0 1.0 5.0 1.0 2.0 3.0 1.0 3.0 3.0 6.0 4.0 4.0 1.0 7.0 6.0 4.0 6.0 2.0 5.0 5.0 3.0 3.0 4.0 0.0 2.0 2.0 0.0 1.0 6.0 9.0 1.0 0.0 2.0 1992.0 0.0 2.0 2.0 1.0 0.0 3.0 7.0 5.0 8.0 4.0 2.0 3.0 3.0 3.0 1167.0 2.0 3.0 2.0 1.0 5.0 5.0 3.0 7.0 5.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 50.0 1.0 0.0 0.0 1.0 0.0 1.0 5.0 8
6 4.0 1.0 5.0 1.0 5.0 1.0 1.0 2.0 1.0 2.0 5.0 4.0 2.0 5.0 1.0 6.0 5.0 3.0 4.0 3.0 3.0 1.0 2.0 2.0 4.0 0.0 1.0 2.0 0.0 2.0 6.0 9.0 1.0 0.0 4.0 1992.0 0.0 4.0 1.0 0.0 0.0 4.0 6.0 2.0 5.0 4.0 2.0 4.0 4.0 3.0 1300.0 3.0 2.0 1.0 0.0 5.0 5.0 2.0 3.0 2.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 70.0 1.0 0.0 0.0 1.0 0.0 1.0 5.0 3
array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True])

nearly 90% of the customers belongs to only 6 clusters out of 15

the customers mainly belongs to clusters 2,8,5,6,9,3

less than 10% of the customer belongs to clusters 7,13,0,1,14,12,10,4,11

PCA helped to show the features which has the largest variance in the data which means trying to map the clusters to the top important features will help to give these clusters a labels , and to understand by of the features

We can map the predicted clusters to the cleaned data set before the standard scaling which helps looking on the raw data , this happens by adding a column to the cleaned data frame with the predictions just as following :

cleaned_data['customerSegemnt']=predictions

this instead of using '.inverse_transorm' for 'PCA' and 'StandardScalar'

I will use plotly to visulize 3d graphs showing the top 4 most important feature for principle component 0 from the PCA analysis for all the clsuters three features will be on x,y,z axis , and the fourth feature will the size of the marker

In [ ]:
# What kinds of people are part of a cluster that is overrepresented in the
# customer data compared to the general population?
# What kinds of people are part of a cluster that is underrepresented in the
# customer data compared to the general population?



generalPopulatio=joblib.load('training_data.pickle')
cleaned_data=joblib.load('cleaned_data.pickle')

generalPopulatio['customerSegemnt']=generalPopulatio['customerSegemnt'].astype(str  )
cleaned_data['customerSegemnt']=cleaned_data['customerSegemnt'].astype(str  )


#largets_cluster=customer_dataProp.nlargest(4).index

#generation	movement_Avantgarde	movement_Mainstream	nation_E	nation_EW	nation_W	tens	ones

X_feature_name='MOBI_REGIO'
Y_feature_name='KBA05_GBZ'
Z_feature_name='LP_STATUS_GROB_1.0'
fourth_feature_name='PLZ8_ANTG3'
 
fig = px.scatter_3d(cleaned_data,
                     x=X_feature_name, y=Y_feature_name, z=Z_feature_name,
                     color="customerSegemnt",#marginal_x="histogram", marginal_y="histogram",
                     symbol="customerSegemnt",
                     size=fourth_feature_name )
fig.show()

fig.write_html('graphs.html')
#fig = px.scatter_3d(generalPopulatio,
#                    x=X_feature_name, y=Y_feature_name, z=Z_feature_name,
#                     color="customerSegemnt",#marginal_x="histogram", marginal_y="histogram",
#                     symbol="customerSegemnt",
#                     size=fourth_feature_name )
#fig.show()

'''
top feature from PCA-PC0
MOBI_REGIO              -0.210659
FINANZ_MINIMALIST       -0.203511
LP_STATUS_GROB_1.0       0.201107
KBA05_ANTG1             -0.197871
KBA05_GBZ               -0.187472
PLZ8_ANTG1              -0.186344
PLZ8_ANTG3               0.185785
HH_EINKOMMEN_SCORE       0.184046
PLZ8_ANTG4               0.178935
ORTSGR_KLS9              0.159325
EWDICHTE                 0.157399
FINANZ_HAUSBAUER         0.142899
PLZ8_GBZ                -0.137776
KONSUMNAEHE             -0.135507
FINANZ_SPARER            0.134426'''
Out[ ]:
'\ntop feature from PCA-PC0\nMOBI_REGIO              -0.210659\nFINANZ_MINIMALIST       -0.203511\nLP_STATUS_GROB_1.0       0.201107\nKBA05_ANTG1             -0.197871\nKBA05_GBZ               -0.187472\nPLZ8_ANTG1              -0.186344\nPLZ8_ANTG3               0.185785\nHH_EINKOMMEN_SCORE       0.184046\nPLZ8_ANTG4               0.178935\nORTSGR_KLS9              0.159325\nEWDICHTE                 0.157399\nFINANZ_HAUSBAUER         0.142899\nPLZ8_GBZ                -0.137776\nKONSUMNAEHE             -0.135507\nFINANZ_SPARER            0.134426'

Discussion 3.3: Compare Customer Data to Demographics Data¶

Double-click this cell and replace this text with your own text, reporting findings and conclusions from the clustering analysis. Can we describe segments of the population that are relatively popular with the mail-order company, or relatively unpopular with the company?

Yes , obvusley can map the features shown in the graph to it is actual meaning

the top four feature for principle component PC0 are :

- MOBI_REGIO :Movement patterns
    -  1: very high movement
    -  2: high movement
    -  3: middle movement
    -  4: low movement
    -  5: very low movement
    -  6: none           

- PLZ8_ANTG3 : Number of 6-10 family houses in the PLZ8 region:
    -  1: lower share of 6-10 family homes
    -  2: average share of 6-10 family homes
    -  3: high share of 6-10 family homes

- LP_STATUS_GROB_1.0  :
    -  0: not low-income earners
    -  1: low-income earners

- KBA05_GBZ: Number of buildings in the microcell
    -  1: 1-2 buildings
    -  2: 3-4 buildings
    -  3: 5-16 buildings
    -  4: 17-22 buildings
    -  5: >=23 buildings

Cluster 2 which has the majority of the customers in the mail list are :¶

- does not include customers with  'very low movement' which has Number of buildings in the microcell<4
- includes low-income earners and not low-income earners   
- have average to high share of family homes



cluster 11 which has a small percentage of the customers

- have  'Middle','Low','very low' movment pattern and 
- average' family houses in the PLZ8 region
- not low-income earners   
- Number of buildings in the microcell >5  

Congratulations on making it this far in the project! Before you finish, make sure to check through the entire notebook from top to bottom to make sure that your analysis follows a logical flow and all of your findings are documented in Discussion cells. Once you've checked over all of your work, you should export the notebook as an HTML document to submit for evaluation. You can do this from the menu, navigating to File -> Download as -> HTML (.html). You will submit both that document and this notebook for your project submission.

In [ ]:
vlcouns=cleaned_data[['nation_EW',	'nation_W',	'nation_E'	,'tens'	,'ones','customerSegemnt']].value_counts()/len(cleaned_data)*100

display( vlcouns  ) 
nation_EW  nation_W  nation_E  tens  ones  customerSegemnt
0.0        0.0       0.0       0.0   0.0   8                  7.141219
                                           5                  4.262415
                                           6                  3.925811
1.0        0.0       0.0       1.0   4.0   2                  3.413155
                               2.0   4.0   2                  3.287316
0.0        0.0       0.0       0.0   0.0   9                  3.189992
                                           3                  2.619687
                                           2                  2.591171
1.0        0.0       0.0       4.0   1.0   2                  2.164682
                                     3.0   2                  1.855353
                               2.0   5.0   2                  1.739432
                               1.0   5.0   2                  1.663185
                               5.0   1.0   2                  1.611733
                               1.0   3.0   2                  1.417706
                               2.0   2.0   2                  1.307984
0.0        0.0       0.0       0.0   0.0   7                  1.202601
1.0        0.0       0.0       4.0   5.0   2                  1.170366
                               1.0   4.0   8                  1.154249
0.0        1.0       0.0       1.0   4.0   2                  1.142471
1.0        0.0       0.0       2.0   4.0   8                  1.092259
                               3.0   4.0   2                  1.014152
                               5.0   4.0   2                  0.964560
0.0        1.0       0.0       2.0   4.0   2                  0.900091
           0.0       0.0       0.0   0.0   13                 0.833762
1.0        0.0       0.0       2.0   3.0   2                  0.789749
                               4.0   1.0   8                  0.727140
                               5.0   5.0   2                  0.718461
                               2.0   4.0   5                  0.677548
                               1.0   4.0   5                  0.649653
                                           6                  0.623617
                               4.0   3.0   8                  0.616178
                               2.0   5.0   8                  0.581464
0.0        1.0       0.0       1.0   5.0   2                  0.578364
1.0        0.0       0.0       2.0   4.0   6                  0.575885
0.0        0.0       0.0       0.0   0.0   0                  0.575885
                                           1                  0.559148
1.0        0.0       0.0       1.0   4.0   9                  0.540551
                               4.0   4.0   2                  0.531872
                               5.0   1.0   8                  0.526913
                               1.0   5.0   8                  0.508316
                               2.0   4.0   9                  0.504597
                                     2.0   8                  0.477321
                               1.0   3.0   8                  0.476701
0.0        0.0       0.0       0.0   0.0   14                 0.465543
1.0        0.0       0.0       1.0   4.0   3                  0.464303
0.0        1.0       0.0       4.0   1.0   2                  0.437648
1.0        0.0       0.0       3.0   5.0   2                  0.429589
                               2.0   4.0   3                  0.428349
                               4.0   1.0   5                  0.409752
                               1.0   2.0   2                  0.409132
                               3.0   1.0   2                  0.406653
0.0        1.0       0.0       4.0   3.0   2                  0.404173
                               2.0   5.0   2                  0.399214
1.0        0.0       0.0       4.0   3.0   5                  0.383097
                                     1.0   6                  0.379377
0.0        1.0       0.0       1.0   4.0   8                  0.368219
                                     3.0   2                  0.363260
1.0        0.0       0.0       4.0   5.0   8                  0.360160
                               5.0   4.0   8                  0.344043
                               4.0   3.0   6                  0.343423
                               5.0   1.0   5                  0.339704
                               2.0   5.0   5                  0.338464
                               3.0   2.0   2                  0.335984
                                     4.0   8                  0.334745
                               1.0   5.0   5                  0.327926
0.0        1.0       0.0       2.0   2.0   2                  0.322967
1.0        0.0       0.0       4.0   1.0   9                  0.322347
0.0        1.0       0.0       2.0   4.0   8                  0.316768
1.0        0.0       0.0       4.0   3.0   9                  0.312428
                               5.0   1.0   6                  0.302510
                               1.0   5.0   6                  0.298791
                               2.0   5.0   6                  0.283293
                               3.0   3.0   2                  0.277714
                               4.0   1.0   3                  0.270275
                               2.0   5.0   9                  0.267176
0.0        0.0       0.0       0.0   0.0   12                 0.263456
1.0        0.0       0.0       1.0   3.0   5                  0.263456
                               2.0   2.0   5                  0.258497
                                     3.0   8                  0.257257
                               4.0   3.0   3                  0.256638
                               1.0   3.0   6                  0.252298
                               5.0   1.0   9                  0.250439
0.0        1.0       0.0       5.0   1.0   2                  0.246719
1.0        0.0       0.0       2.0   2.0   6                  0.241760
                               5.0   5.0   8                  0.241140
0.0        1.0       0.0       3.0   4.0   2                  0.240520
           0.0       0.0       0.0   0.0   10                 0.234941
                                           11                 0.231222
           1.0       0.0       1.0   4.0   5                  0.231222
1.0        0.0       0.0       1.0   5.0   9                  0.228122
0.0        1.0       0.0       2.0   3.0   2                  0.226263
1.0        0.0       0.0       2.0   5.0   3                  0.224403
                               4.0   5.0   5                  0.221923
0.0        1.0       0.0       1.0   4.0   6                  0.221303
1.0        0.0       0.0       5.0   1.0   3                  0.219444
0.0        0.0       0.0       0.0   0.0   4                  0.216344
1.0        0.0       0.0       2.0   2.0   9                  0.212005
                               1.0   4.0   7                  0.211385
0.0        1.0       0.0       1.0   5.0   8                  0.208286
1.0        0.0       0.0       1.0   3.0   9                  0.206426
                                     5.0   3                  0.205806
                               5.0   2.0   2                  0.201467
                               2.0   4.0   7                  0.200847
                               4.0   5.0   6                  0.199607
                               5.0   4.0   5                  0.196507
                               3.0   4.0   5                  0.191548
                               4.0   4.0   8                  0.187829
                               5.0   4.0   6                  0.186589
                               2.0   2.0   3                  0.183490
                               1.0   3.0   3                  0.179770
0.0        1.0       0.0       1.0   2.0   2                  0.177911
1.0        0.0       0.0       2.0   3.0   5                  0.165513
                               4.0   5.0   9                  0.163033
0.0        1.0       0.0       2.0   4.0   6                  0.161793
                               1.0   4.0   3                  0.161173
                               2.0   4.0   5                  0.159934
1.0        0.0       0.0       3.0   4.0   6                  0.158074
                                           9                  0.157454
0.0        1.0       0.0       1.0   4.0   9                  0.156214
1.0        0.0       0.0       1.0   2.0   8                  0.155594
                               5.0   5.0   5                  0.153115
                               2.0   3.0   6                  0.152495
                               3.0   5.0   8                  0.151875
                                     1.0   8                  0.151255
                               4.0   5.0   3                  0.147536
0.0        1.0       0.0       2.0   5.0   8                  0.146296
1.0        0.0       0.0       1.0   4.0   13                 0.145676
0.0        1.0       0.0       4.0   1.0   8                  0.139477
                               2.0   4.0   3                  0.136997
1.0        0.0       0.0       5.0   4.0   9                  0.135758
                               2.0   3.0   9                  0.134518
0.0        1.0       0.0       5.0   4.0   2                  0.134518
1.0        0.0       0.0       2.0   4.0   13                 0.132658
                               4.0   1.0   7                  0.130798
0.0        1.0       0.0       2.0   4.0   9                  0.129559
1.0        0.0       0.0       5.0   4.0   3                  0.127699
0.0        1.0       0.0       4.0   3.0   8                  0.123360
1.0        0.0       0.0       5.0   5.0   6                  0.123360
0.0        1.0       0.0       1.0   3.0   8                  0.122120
1.0        0.0       0.0       3.0   4.0   3                  0.120880
0.0        1.0       0.0       4.0   4.0   2                  0.119640
                               3.0   1.0   2                  0.118400
                               1.0   5.0   5                  0.117781
1.0        0.0       0.0       3.0   2.0   8                  0.114061
                               2.0   4.0   0                  0.114061
                               5.0   5.0   9                  0.110962
0.0        1.0       0.0       2.0   2.0   8                  0.110342
                               1.0   5.0   6                  0.110342
1.0        0.0       0.0       4.0   3.0   7                  0.109722
                               2.0   3.0   3                  0.109722
                               1.0   4.0   0                  0.107862
                               4.0   4.0   6                  0.106002
                               1.0   5.0   7                  0.103523
0.0        1.0       0.0       4.0   5.0   2                  0.102903
1.0        0.0       0.0       3.0   3.0   8                  0.097944
                               5.0   5.0   3                  0.097324
                               3.0   5.0   5                  0.097324
                               2.0   5.0   7                  0.096704
                               4.0   4.0   5                  0.095464
                               5.0   1.0   7                  0.094844
0.0        1.0       0.0       3.0   5.0   2                  0.094224
                                     4.0   8                  0.092985
1.0        0.0       0.0       1.0   2.0   5                  0.092365
0.0        1.0       0.0       2.0   5.0   5                  0.092365
                               1.0   5.0   9                  0.090505
1.0        0.0       0.0       3.0   1.0   5                  0.088025
                               2.0   4.0   1                  0.083686
0.0        1.0       0.0       5.0   1.0   8                  0.081826
1.0        0.0       0.0       2.0   5.0   13                 0.081826
0.0        1.0       0.0       4.0   1.0   6                  0.081207
                               1.0   5.0   3                  0.080587
1.0        0.0       0.0       3.0   1.0   6                  0.080587
                                     2.0   5                  0.080587
0.0        1.0       0.0       2.0   3.0   8                  0.080587
1.0        0.0       0.0       2.0   2.0   7                  0.080587
0.0        1.0       0.0       4.0   1.0   5                  0.078727
1.0        0.0       0.0       1.0   3.0   7                  0.078727
                               4.0   3.0   13                 0.076247
0.0        1.0       0.0       4.0   3.0   5                  0.076247
1.0        0.0       0.0       1.0   4.0   1                  0.076247
                                     2.0   6                  0.075627
0.0        1.0       0.0       2.0   5.0   6                  0.075627
                                     2.0   6                  0.074388
1.0        0.0       0.0       3.0   5.0   6                  0.073768
                               1.0   4.0   14                 0.073148
                               4.0   4.0   9                  0.073148
                                     1.0   13                 0.071908
                                     4.0   3                  0.071288
0.0        0.0       1.0       1.0   4.0   2                  0.071288
           1.0       0.0       1.0   3.0   6                  0.071288
1.0        0.0       0.0       5.0   2.0   8                  0.070668
0.0        1.0       0.0       1.0   3.0   5                  0.069429
1.0        0.0       0.0       1.0   2.0   9                  0.068809
0.0        1.0       0.0       4.0   1.0   9                  0.068189
                                     3.0   6                  0.067569
                                     1.0   3                  0.067569
1.0        0.0       0.0       2.0   4.0   14                 0.066949
0.0        1.0       0.0       3.0   2.0   2                  0.066949
                                     4.0   5                  0.063849
                               1.0   2.0   8                  0.061990
1.0        0.0       0.0       3.0   2.0   6                  0.061990
                                     5.0   9                  0.061370
0.0        1.0       0.0       4.0   3.0   9                  0.059510
1.0        0.0       0.0       1.0   5.0   13                 0.058890
                               4.0   1.0   0                  0.058270
                                     3.0   0                  0.057650
0.0        1.0       0.0       1.0   4.0   7                  0.057650
                               2.0   2.0   5                  0.057650
                                     5.0   3                  0.057031
1.0        0.0       0.0       4.0   1.0   1                  0.057031
                               3.0   3.0   6                  0.056411
0.0        1.0       0.0       1.0   3.0   9                  0.055791
1.0        0.0       0.0       3.0   5.0   3                  0.055171
                                     1.0   9                  0.054551
0.0        1.0       0.0       3.0   3.0   2                  0.054551
           0.0       1.0       4.0   1.0   2                  0.054551
           1.0       0.0       2.0   5.0   9                  0.054551
1.0        0.0       0.0       2.0   3.0   7                  0.054551
                               4.0   5.0   7                  0.053931
                               3.0   3.0   5                  0.053931
0.0        1.0       0.0       2.0   3.0   6                  0.052691
1.0        0.0       0.0       1.0   2.0   3                  0.052071
                               5.0   1.0   13                 0.052071
                               2.0   2.0   13                 0.051451
                                     4.0   12                 0.050832
                               1.0   5.0   0                  0.048972
0.0        0.0       1.0       2.0   5.0   2                  0.048352
           1.0       0.0       2.0   2.0   9                  0.048352
1.0        0.0       0.0       5.0   2.0   5                  0.047732
                               4.0   3.0   1                  0.047732
0.0        0.0       1.0       2.0   4.0   2                  0.047112
1.0        0.0       0.0       2.0   5.0   1                  0.046492
                               1.0   4.0   12                 0.046492
                               2.0   5.0   0                  0.046492
0.0        1.0       0.0       5.0   1.0   5                  0.045872
                                     4.0   8                  0.045872
1.0        0.0       0.0       4.0   1.0   14                 0.045253
                               3.0   4.0   7                  0.045253
                                     3.0   9                  0.045253
                                     2.0   9                  0.044633
0.0        1.0       0.0       4.0   3.0   3                  0.044633
1.0        0.0       0.0       5.0   5.0   7                  0.044633
0.0        1.0       0.0       5.0   1.0   6                  0.044013
1.0        0.0       0.0       3.0   1.0   3                  0.043393
0.0        1.0       0.0       1.0   2.0   5                  0.043393
                                     3.0   3                  0.043393
                               5.0   5.0   2                  0.042773
                               2.0   2.0   3                  0.042773
1.0        0.0       0.0       5.0   1.0   1                  0.042773
0.0        1.0       0.0       4.0   4.0   8                  0.042153
1.0        0.0       0.0       4.0   5.0   13                 0.042153
                               5.0   4.0   7                  0.042153
                                           13                 0.042153
0.0        1.0       0.0       2.0   4.0   7                  0.042153
                               3.0   4.0   9                  0.041533
                               2.0   3.0   5                  0.041533
1.0        0.0       0.0       1.0   3.0   13                 0.041533
                                     4.0   10                 0.040913
                                     3.0   0                  0.040913
                               3.0   4.0   13                 0.039673
                               1.0   3.0   1                  0.039054
                               3.0   2.0   3                  0.039054
0.0        1.0       0.0       1.0   2.0   6                  0.039054
           0.0       1.0       5.0   1.0   2                  0.038434
1.0        0.0       0.0       2.0   4.0   11                 0.038434
                               5.0   1.0   0                  0.038434
0.0        1.0       0.0       5.0   2.0   2                  0.037814
                               2.0   3.0   9                  0.037814
1.0        0.0       0.0       4.0   3.0   14                 0.037814
                               1.0   4.0   11                 0.037194
                               2.0   2.0   0                  0.036574
0.0        1.0       0.0       5.0   4.0   6                  0.036574
1.0        0.0       0.0       1.0   5.0   1                  0.035954
0.0        1.0       0.0       3.0   4.0   6                  0.035954
1.0        0.0       0.0       1.0   4.0   4                  0.035334
0.0        1.0       0.0       1.0   4.0   13                 0.035334
1.0        0.0       0.0       4.0   5.0   0                  0.034714
0.0        1.0       0.0       2.0   3.0   3                  0.034714
1.0        0.0       0.0       5.0   2.0   6                  0.034714
                               2.0   4.0   10                 0.034094
0.0        1.0       0.0       4.0   5.0   8                  0.033474
                               3.0   1.0   8                  0.033474
1.0        0.0       0.0       3.0   3.0   3                  0.032855
                               2.0   2.0   1                  0.032855
                                     5.0   14                 0.032855
0.0        1.0       0.0       2.0   4.0   13                 0.032235
                               1.0   5.0   7                  0.032235
                               3.0   4.0   3                  0.031615
           0.0       1.0       3.0   4.0   2                  0.030995
1.0        0.0       0.0       5.0   2.0   3                  0.030995
                               2.0   5.0   12                 0.030375
0.0        0.0       1.0       1.0   3.0   2                  0.030375
           1.0       0.0       5.0   1.0   3                  0.030375
1.0        0.0       0.0       2.0   3.0   13                 0.030375
0.0        1.0       0.0       4.0   1.0   7                  0.029755
1.0        0.0       0.0       3.0   4.0   0                  0.029755
                               1.0   5.0   14                 0.029755
0.0        1.0       0.0       5.0   1.0   9                  0.029135
                               3.0   5.0   8                  0.029135
1.0        0.0       0.0       5.0   1.0   14                 0.027895
0.0        1.0       0.0       4.0   3.0   7                  0.027275
1.0        0.0       0.0       4.0   5.0   1                  0.027275
0.0        0.0       1.0       1.0   5.0   2                  0.027275
1.0        0.0       0.0       4.0   1.0   12                 0.026656
                               5.0   5.0   13                 0.026656
0.0        1.0       0.0       1.0   4.0   1                  0.026656
1.0        0.0       0.0       2.0   4.0   4                  0.026656
0.0        1.0       0.0       1.0   4.0   0                  0.026656
1.0        0.0       0.0       4.0   4.0   7                  0.026036
                               3.0   4.0   1                  0.026036
0.0        1.0       0.0       5.0   4.0   5                  0.026036
           0.0       1.0       4.0   3.0   2                  0.025416
1.0        0.0       0.0       3.0   5.0   7                  0.025416
                               1.0   2.0   7                  0.024796
0.0        1.0       0.0       1.0   2.0   9                  0.024796
1.0        0.0       0.0       4.0   5.0   14                 0.024176
0.0        1.0       0.0       2.0   4.0   0                  0.024176
1.0        0.0       0.0       2.0   3.0   1                  0.024176
                               5.0   4.0   1                  0.024176
                                     2.0   9                  0.023556
                               4.0   4.0   13                 0.023556
0.0        0.0       1.0       4.0   1.0   8                  0.023556
           1.0       0.0       2.0   4.0   1                  0.023556
1.0        0.0       0.0       5.0   4.0   0                  0.022936
0.0        1.0       0.0       4.0   5.0   6                  0.022936
                               1.0   3.0   7                  0.022936
                               2.0   5.0   7                  0.022936
1.0        0.0       0.0       2.0   2.0   14                 0.022936
0.0        1.0       0.0       1.0   5.0   1                  0.022316
1.0        0.0       0.0       5.0   4.0   14                 0.022316
0.0        1.0       0.0       3.0   5.0   6                  0.021696
                               4.0   4.0   9                  0.021696
1.0        0.0       0.0       4.0   3.0   12                 0.021696
0.0        1.0       0.0       2.0   4.0   14                 0.021696
1.0        0.0       0.0       4.0   1.0   11                 0.021696
                                     3.0   4                  0.021077
                               2.0   5.0   4                  0.021077
0.0        1.0       0.0       1.0   2.0   3                  0.021077
                               3.0   3.0   8                  0.021077
                               4.0   5.0   5                  0.021077
1.0        0.0       0.0       5.0   5.0   1                  0.021077
0.0        1.0       0.0       5.0   4.0   3                  0.020457
1.0        0.0       0.0       1.0   3.0   14                 0.020457
0.0        0.0       1.0       4.0   5.0   2                  0.020457
           1.0       0.0       2.0   2.0   7                  0.020457
1.0        0.0       0.0       1.0   2.0   13                 0.020457
                               4.0   1.0   4                  0.019837
0.0        1.0       0.0       3.0   1.0   5                  0.019837
1.0        0.0       0.0       2.0   3.0   0                  0.019837
                               4.0   5.0   12                 0.019837
0.0        1.0       0.0       3.0   2.0   8                  0.019837
                               5.0   4.0   9                  0.019217
1.0        0.0       0.0       4.0   1.0   10                 0.019217
                               3.0   3.0   7                  0.019217
0.0        1.0       0.0       3.0   1.0   6                  0.018597
                               1.0   4.0   14                 0.018597
           0.0       1.0       5.0   4.0   2                  0.018597
1.0        0.0       0.0       1.0   3.0   11                 0.017977
                               4.0   3.0   11                 0.017977
                               1.0   5.0   10                 0.017977
0.0        0.0       1.0       1.0   4.0   8                  0.017977
1.0        0.0       0.0       1.0   5.0   12                 0.017977
                                           4                  0.017977
                               2.0   5.0   10                 0.017977
                               5.0   1.0   10                 0.017977
                                     2.0   7                  0.017357
                               3.0   4.0   14                 0.017357
0.0        1.0       0.0       3.0   5.0   9                  0.017357
1.0        0.0       0.0       1.0   3.0   12                 0.017357
0.0        1.0       0.0       4.0   4.0   5                  0.017357
1.0        0.0       0.0       5.0   1.0   4                  0.016737
                               2.0   5.0   11                 0.016737
0.0        1.0       0.0       3.0   3.0   6                  0.016737
1.0        0.0       0.0       5.0   1.0   11                 0.016737
                                     5.0   0                  0.016737
                               2.0   3.0   14                 0.016737
0.0        1.0       0.0       3.0   5.0   5                  0.016737
           0.0       1.0       2.0   5.0   8                  0.016117
1.0        0.0       0.0       4.0   4.0   14                 0.016117
0.0        1.0       0.0       2.0   3.0   7                  0.016117
1.0        0.0       0.0       3.0   1.0   7                  0.016117
0.0        0.0       1.0       1.0   4.0   5                  0.016117
1.0        0.0       0.0       2.0   2.0   4                  0.016117
                               4.0   5.0   4                  0.016117
0.0        1.0       0.0       4.0   4.0   6                  0.016117
                               3.0   3.0   5                  0.015497
                               4.0   5.0   3                  0.015497
                                     4.0   3                  0.015497
1.0        0.0       0.0       3.0   1.0   0                  0.015497
0.0        1.0       0.0       4.0   1.0   13                 0.014878
1.0        0.0       0.0       1.0   3.0   10                 0.014878
                               2.0   2.0   10                 0.014878
                               4.0   4.0   0                  0.014878
0.0        1.0       0.0       3.0   2.0   6                  0.014878
1.0        0.0       0.0       3.0   2.0   7                  0.014258
0.0        0.0       1.0       5.0   1.0   8                  0.014258
1.0        0.0       0.0       3.0   1.0   13                 0.014258
                               5.0   1.0   12                 0.014258
0.0        1.0       0.0       1.0   3.0   13                 0.014258
           0.0       1.0       3.0   1.0   2                  0.014258
1.0        0.0       0.0       2.0   2.0   12                 0.014258
                               4.0   4.0   1                  0.013638
0.0        1.0       0.0       4.0   1.0   0                  0.013638
           0.0       1.0       5.0   5.0   2                  0.013638
           1.0       0.0       3.0   1.0   9                  0.013638
1.0        0.0       0.0       4.0   3.0   10                 0.013638
                                     5.0   11                 0.013638
0.0        1.0       0.0       5.0   1.0   7                  0.013638
1.0        0.0       0.0       3.0   5.0   13                 0.013018
0.0        1.0       0.0       4.0   1.0   14                 0.013018
1.0        0.0       0.0       2.0   2.0   11                 0.013018
0.0        1.0       0.0       4.0   5.0   9                  0.013018
                               1.0   5.0   13                 0.013018
1.0        0.0       0.0       5.0   4.0   4                  0.012398
0.0        1.0       0.0       1.0   5.0   0                  0.012398
1.0        0.0       0.0       3.0   5.0   1                  0.012398
                               1.0   3.0   4                  0.012398
0.0        1.0       0.0       2.0   2.0   1                  0.012398
1.0        0.0       0.0       2.0   3.0   12                 0.012398
0.0        1.0       0.0       4.0   3.0   1                  0.012398
           0.0       1.0       4.0   1.0   5                  0.012398
           1.0       0.0       2.0   2.0   13                 0.012398
                               3.0   4.0   7                  0.012398
                                     2.0   5                  0.012398
1.0        0.0       0.0       1.0   2.0   1                  0.011778
                               4.0   5.0   10                 0.011778
                               5.0   5.0   14                 0.011778
                               1.0   2.0   0                  0.011778
                               2.0   3.0   10                 0.011778
0.0        1.0       0.0       1.0   4.0   11                 0.011778
                               2.0   5.0   0                  0.011778
1.0        0.0       0.0       1.0   5.0   11                 0.011778
0.0        1.0       0.0       1.0   3.0   14                 0.011778
           0.0       1.0       1.0   4.0   6                  0.011778
1.0        0.0       0.0       3.0   4.0   12                 0.011778
0.0        1.0       0.0       3.0   3.0   9                  0.011778
                               4.0   3.0   14                 0.011778
                               1.0   5.0   14                 0.011158
           0.0       1.0       2.0   4.0   8                  0.011158
1.0        0.0       0.0       1.0   2.0   14                 0.011158
0.0        1.0       0.0       2.0   5.0   14                 0.011158
                               4.0   1.0   1                  0.011158
           0.0       1.0       5.0   4.0   8                  0.011158
           1.0       0.0       2.0   5.0   13                 0.011158
                               5.0   2.0   8                  0.010538
1.0        0.0       0.0       5.0   5.0   4                  0.010538
                               2.0   3.0   4                  0.010538
                               3.0   4.0   11                 0.010538
0.0        1.0       0.0       3.0   1.0   3                  0.010538
                               5.0   2.0   6                  0.010538
                               2.0   3.0   0                  0.010538
1.0        0.0       0.0       3.0   1.0   14                 0.010538
                               5.0   5.0   10                 0.010538
0.0        1.0       0.0       1.0   4.0   10                 0.010538
                               3.0   3.0   3                  0.010538
           0.0       1.0       4.0   4.0   2                  0.009918
           1.0       0.0       4.0   3.0   0                  0.009918
           0.0       1.0       1.0   4.0   3                  0.009918
           1.0       0.0       3.0   5.0   3                  0.009918
           0.0       1.0       2.0   4.0   5                  0.009918
           1.0       0.0       1.0   5.0   10                 0.009918
                                     2.0   13                 0.009918
                               2.0   4.0   12                 0.009918
                               4.0   3.0   13                 0.009918
                               3.0   2.0   9                  0.009918
           0.0       1.0       1.0   3.0   8                  0.009918
           1.0       0.0       1.0   4.0   4                  0.009298
                                     3.0   1                  0.009298
                               2.0   4.0   10                 0.009298
                               1.0   2.0   7                  0.009298
           0.0       1.0       1.0   5.0   8                  0.009298
1.0        0.0       0.0       3.0   5.0   0                  0.009298
                               4.0   4.0   11                 0.009298
                               2.0   3.0   11                 0.008679
                               5.0   4.0   12                 0.008679
0.0        1.0       0.0       4.0   1.0   10                 0.008679
                               1.0   3.0   0                  0.008679
           0.0       1.0       2.0   5.0   5                  0.008679
1.0        0.0       0.0       3.0   3.0   13                 0.008679
0.0        0.0       1.0       2.0   2.0   2                  0.008679
           1.0       0.0       5.0   5.0   8                  0.008679
1.0        0.0       0.0       5.0   4.0   10                 0.008059
0.0        1.0       0.0       3.0   5.0   7                  0.008059
                                     4.0   13                 0.008059
           0.0       1.0       4.0   3.0   5                  0.008059
           1.0       0.0       2.0   5.0   1                  0.008059
1.0        0.0       0.0       5.0   4.0   11                 0.008059
0.0        0.0       1.0       3.0   4.0   6                  0.008059
                                           8                  0.008059
1.0        0.0       0.0       3.0   3.0   1                  0.008059
                                     4.0   4                  0.008059
0.0        0.0       1.0       1.0   3.0   5                  0.008059
1.0        0.0       0.0       3.0   4.0   10                 0.008059
0.0        1.0       0.0       2.0   4.0   4                  0.008059
1.0        0.0       0.0       5.0   2.0   13                 0.008059
0.0        0.0       1.0       1.0   4.0   9                  0.008059
1.0        0.0       0.0       3.0   3.0   0                  0.008059
                               1.0   2.0   12                 0.007439
0.0        0.0       1.0       5.0   1.0   5                  0.007439
                               1.0   3.0   6                  0.007439
1.0        0.0       0.0       3.0   2.0   14                 0.007439
                                     3.0   14                 0.007439
0.0        1.0       0.0       1.0   2.0   0                  0.007439
           0.0       1.0       2.0   5.0   3                  0.007439
1.0        0.0       0.0       5.0   5.0   12                 0.007439
                               4.0   4.0   12                 0.007439
0.0        1.0       0.0       5.0   1.0   13                 0.007439
           0.0       1.0       2.0   3.0   2                  0.007439
                                     4.0   6                  0.007439
           1.0       0.0       5.0   2.0   5                  0.007439
                                     1.0   0                  0.007439
                               2.0   2.0   0                  0.007439
           0.0       1.0       4.0   5.0   5                  0.006819
                                     3.0   8                  0.006819
                               2.0   4.0   9                  0.006819
           1.0       0.0       5.0   4.0   7                  0.006819
1.0        0.0       0.0       3.0   1.0   12                 0.006819
                                     2.0   1                  0.006819
0.0        1.0       0.0       1.0   5.0   12                 0.006819
           0.0       1.0       4.0   5.0   8                  0.006819
1.0        0.0       0.0       4.0   4.0   4                  0.006819
                               3.0   2.0   13                 0.006199
0.0        0.0       1.0       5.0   2.0   2                  0.006199
                               1.0   5.0   5                  0.006199
           1.0       0.0       1.0   4.0   12                 0.006199
                                     3.0   12                 0.006199
1.0        0.0       0.0       3.0   5.0   14                 0.006199
                                           4                  0.006199
                                     1.0   10                 0.006199
0.0        1.0       0.0       5.0   4.0   0                  0.006199
                               2.0   3.0   1                  0.006199
                               4.0   1.0   4                  0.006199
           0.0       1.0       4.0   1.0   9                  0.006199
           1.0       0.0       5.0   5.0   5                  0.006199
           0.0       1.0       3.0   5.0   2                  0.006199
           1.0       0.0       3.0   2.0   3                  0.006199
                               4.0   4.0   13                 0.006199
                               3.0   4.0   14                 0.006199
                               5.0   5.0   3                  0.005579
1.0        0.0       0.0       3.0   5.0   12                 0.005579
0.0        1.0       0.0       5.0   5.0   6                  0.005579
                               1.0   5.0   4                  0.005579
           0.0       1.0       1.0   5.0   9                  0.005579
1.0        0.0       0.0       3.0   3.0   12                 0.005579
0.0        0.0       1.0       5.0   1.0   6                  0.005579
           1.0       0.0       2.0   5.0   11                 0.005579
1.0        0.0       0.0       3.0   2.0   0                  0.005579
0.0        1.0       0.0       5.0   1.0   1                  0.005579
                               2.0   2.0   14                 0.005579
                               4.0   1.0   12                 0.005579
                               5.0   1.0   4                  0.005579
                               3.0   1.0   7                  0.005579
1.0        0.0       0.0       1.0   2.0   4                  0.005579
0.0        1.0       0.0       2.0   4.0   11                 0.005579
                               3.0   4.0   1                  0.005579
           0.0       1.0       2.0   5.0   6                  0.004959
1.0        0.0       0.0       5.0   2.0   0                  0.004959
                               3.0   2.0   10                 0.004959
                                     1.0   11                 0.004959
0.0        0.0       1.0       5.0   1.0   9                  0.004959
           1.0       0.0       3.0   4.0   0                  0.004959
           0.0       1.0       5.0   4.0   6                  0.004959
                                           3                  0.004959
           1.0       0.0       4.0   3.0   4                  0.004959
           0.0       1.0       4.0   1.0   6                  0.004959
                               5.0   5.0   6                  0.004959
           1.0       0.0       2.0   3.0   13                 0.004959
                               1.0   2.0   1                  0.004959
                                           14                 0.004959
           0.0       1.0       2.0   4.0   3                  0.004959
                               4.0   1.0   3                  0.004959
           1.0       0.0       5.0   4.0   14                 0.004959
                                     1.0   10                 0.004339
                               4.0   5.0   7                  0.004339
1.0        0.0       0.0       3.0   1.0   1                  0.004339
                               5.0   5.0   11                 0.004339
0.0        1.0       0.0       3.0   5.0   13                 0.004339
1.0        0.0       0.0       5.0   2.0   1                  0.004339
0.0        0.0       1.0       4.0   4.0   8                  0.004339
                               1.0   3.0   9                  0.004339
           1.0       0.0       3.0   3.0   13                 0.004339
                               4.0   3.0   11                 0.004339
           0.0       1.0       1.0   5.0   3                  0.004339
                               2.0   4.0   7                  0.004339
1.0        0.0       0.0       3.0   5.0   10                 0.004339
0.0        0.0       1.0       3.0   4.0   5                  0.004339
1.0        0.0       0.0       3.0   5.0   11                 0.004339
0.0        0.0       1.0       1.0   4.0   7                  0.004339
           1.0       0.0       1.0   5.0   11                 0.004339
                               2.0   5.0   10                 0.004339
           0.0       1.0       3.0   1.0   9                  0.004339
           1.0       0.0       5.0   4.0   1                  0.004339
           0.0       1.0       4.0   1.0   13                 0.004339
           1.0       0.0       5.0   5.0   9                  0.004339
1.0        0.0       0.0       1.0   2.0   11                 0.004339
0.0        1.0       0.0       5.0   5.0   0                  0.003719
1.0        0.0       0.0       5.0   2.0   14                 0.003719
0.0        0.0       1.0       4.0   3.0   6                  0.003719
           1.0       0.0       4.0   1.0   11                 0.003719
                               2.0   2.0   4                  0.003719
           0.0       1.0       4.0   5.0   6                  0.003719
           1.0       0.0       4.0   3.0   10                 0.003719
                               3.0   4.0   10                 0.003719
1.0        0.0       0.0       4.0   4.0   10                 0.003719
0.0        1.0       0.0       3.0   1.0   1                  0.003719
                               4.0   4.0   7                  0.003719
           0.0       1.0       2.0   5.0   9                  0.003719
           1.0       0.0       3.0   3.0   0                  0.003719
                               1.0   3.0   10                 0.003719
           0.0       1.0       5.0   5.0   3                  0.003719
           1.0       0.0       5.0   1.0   14                 0.003719
                               1.0   3.0   4                  0.003719
1.0        0.0       0.0       1.0   2.0   10                 0.003719
                               3.0   3.0   4                  0.003719
0.0        1.0       0.0       2.0   5.0   4                  0.003719
                                           12                 0.003719
1.0        0.0       0.0       3.0   2.0   11                 0.003719
0.0        1.0       0.0       2.0   3.0   10                 0.003719
                               4.0   5.0   13                 0.003099
1.0        0.0       0.0       5.0   2.0   4                  0.003099
0.0        1.0       0.0       4.0   3.0   12                 0.003099
           0.0       1.0       3.0   1.0   5                  0.003099
                                           8                  0.003099
1.0        0.0       0.0       3.0   2.0   12                 0.003099
0.0        0.0       1.0       1.0   5.0   6                  0.003099
                               4.0   1.0   1                  0.003099
           1.0       0.0       5.0   4.0   13                 0.003099
1.0        0.0       0.0       3.0   1.0   4                  0.003099
                                     2.0   4                  0.003099
0.0        1.0       0.0       2.0   3.0   14                 0.003099
           0.0       1.0       4.0   3.0   9                  0.003099
           1.0       0.0       3.0   1.0   12                 0.003099
                               2.0   2.0   12                 0.003099
                                           11                 0.003099
           0.0       1.0       3.0   5.0   8                  0.003099
           1.0       0.0       5.0   1.0   11                 0.003099
           0.0       1.0       5.0   4.0   9                  0.003099
                               4.0   5.0   3                  0.003099
           1.0       0.0       3.0   3.0   14                 0.003099
           0.0       1.0       4.0   1.0   7                  0.003099
           1.0       0.0       3.0   5.0   1                  0.002480
           0.0       1.0       5.0   1.0   3                  0.002480
1.0        0.0       0.0       3.0   3.0   10                 0.002480
0.0        0.0       1.0       3.0   1.0   6                  0.002480
                               4.0   5.0   9                  0.002480
           1.0       0.0       3.0   2.0   7                  0.002480
           0.0       1.0       3.0   5.0   5                  0.002480
                               4.0   1.0   14                 0.002480
                               1.0   4.0   13                 0.002480
           1.0       0.0       5.0   5.0   7                  0.002480
           0.0       1.0       1.0   4.0   0                  0.002480
                               5.0   4.0   5                  0.002480
                               3.0   4.0   3                  0.002480
           1.0       0.0       2.0   3.0   11                 0.002480
           0.0       1.0       2.0   5.0   7                  0.002480
                               3.0   4.0   14                 0.002480
                               4.0   4.0   5                  0.002480
                               5.0   1.0   7                  0.002480
                               1.0   3.0   3                  0.002480
                               5.0   5.0   5                  0.002480
           1.0       0.0       2.0   2.0   10                 0.002480
           0.0       1.0       3.0   3.0   5                  0.002480
                                     4.0   9                  0.002480
           1.0       0.0       3.0   1.0   0                  0.002480
           0.0       1.0       1.0   3.0   0                  0.002480
           1.0       0.0       3.0   1.0   13                 0.002480
                               4.0   5.0   14                 0.002480
1.0        0.0       0.0       5.0   2.0   12                 0.002480
0.0        0.0       1.0       5.0   1.0   13                 0.002480
           1.0       0.0       4.0   4.0   14                 0.002480
                               5.0   4.0   4                  0.002480
                               3.0   5.0   0                  0.002480
           0.0       1.0       4.0   4.0   3                  0.001860
           1.0       0.0       1.0   2.0   12                 0.001860
           0.0       1.0       3.0   3.0   2                  0.001860
                               2.0   3.0   5                  0.001860
           1.0       0.0       3.0   1.0   11                 0.001860
                                           10                 0.001860
           0.0       1.0       2.0   4.0   0                  0.001860
           1.0       0.0       3.0   4.0   11                 0.001860
                               1.0   2.0   11                 0.001860
                               4.0   4.0   0                  0.001860
           0.0       1.0       3.0   4.0   7                  0.001860
           1.0       0.0       5.0   2.0   13                 0.001860
           0.0       1.0       4.0   1.0   12                 0.001860
                                     4.0   6                  0.001860
           1.0       0.0       1.0   3.0   11                 0.001860
           0.0       1.0       4.0   3.0   3                  0.001860
           1.0       0.0       5.0   2.0   9                  0.001860
                                           3                  0.001860
                               3.0   4.0   4                  0.001860
           0.0       1.0       2.0   5.0   13                 0.001860
           1.0       0.0       5.0   2.0   0                  0.001860
           0.0       1.0       5.0   5.0   9                  0.001860
           1.0       0.0       1.0   2.0   10                 0.001860
           0.0       1.0       5.0   5.0   8                  0.001860
                               2.0   2.0   8                  0.001860
           1.0       0.0       4.0   4.0   4                  0.001860
           0.0       1.0       3.0   3.0   9                  0.001860
                               4.0   4.0   9                  0.001860
                               1.0   3.0   7                  0.001860
           1.0       0.0       3.0   3.0   1                  0.001860
                               5.0   4.0   11                 0.001860
1.0        0.0       0.0       3.0   3.0   11                 0.001860
0.0        1.0       0.0       3.0   3.0   12                 0.001860
                                     2.0   13                 0.001860
                                     1.0   14                 0.001860
           0.0       1.0       4.0   5.0   13                 0.001860
                               5.0   2.0   8                  0.001860
           1.0       0.0       3.0   3.0   7                  0.001860
                                     2.0   10                 0.001240
           0.0       1.0       3.0   5.0   6                  0.001240
                               5.0   1.0   0                  0.001240
1.0        0.0       0.0       5.0   2.0   11                 0.001240
0.0        0.0       1.0       1.0   3.0   4                  0.001240
                               4.0   4.0   13                 0.001240
           1.0       0.0       3.0   2.0   1                  0.001240
           0.0       1.0       4.0   3.0   7                  0.001240
                               1.0   4.0   1                  0.001240
                                           14                 0.001240
                               4.0   5.0   7                  0.001240
                                     4.0   14                 0.001240
                               1.0   4.0   10                 0.001240
           1.0       0.0       5.0   2.0   14                 0.001240
           0.0       1.0       5.0   1.0   12                 0.001240
                               1.0   5.0   14                 0.001240
           1.0       0.0       5.0   5.0   14                 0.001240
           0.0       1.0       5.0   4.0   1                  0.001240
                               3.0   4.0   0                  0.001240
           1.0       0.0       2.0   3.0   12                 0.001240
           0.0       1.0       3.0   2.0   2                  0.001240
                               5.0   4.0   14                 0.001240
                                           7                  0.001240
                               4.0   1.0   0                  0.001240
           1.0       0.0       4.0   4.0   10                 0.001240
                                           12                 0.001240
           0.0       1.0       3.0   3.0   6                  0.001240
           1.0       0.0       4.0   5.0   0                  0.001240
           0.0       1.0       2.0   2.0   5                  0.001240
                               5.0   5.0   7                  0.001240
                               2.0   2.0   6                  0.001240
                                     5.0   11                 0.001240
                                           1                  0.001240
                                           0                  0.001240
                                     4.0   1                  0.001240
           1.0       0.0       5.0   1.0   12                 0.001240
                                     2.0   7                  0.001240
           0.0       1.0       5.0   2.0   6                  0.001240
                                     5.0   0                  0.001240
                                     4.0   13                 0.001240
           1.0       0.0       2.0   3.0   4                  0.001240
           0.0       1.0       1.0   5.0   13                 0.001240
           1.0       0.0       3.0   5.0   4                  0.001240
                                           14                 0.001240
           0.0       1.0       5.0   2.0   14                 0.001240
                               1.0   5.0   11                 0.001240
           1.0       0.0       5.0   5.0   4                  0.001240
           0.0       1.0       1.0   4.0   4                  0.000620
                               3.0   5.0   9                  0.000620
                               2.0   3.0   8                  0.000620
                               1.0   3.0   1                  0.000620
                               2.0   3.0   7                  0.000620
           1.0       0.0       3.0   5.0   11                 0.000620
                                           12                 0.000620
           0.0       1.0       2.0   3.0   3                  0.000620
                               1.0   5.0   1                  0.000620
                               4.0   3.0   13                 0.000620
                                           10                 0.000620
                               3.0   5.0   13                 0.000620
                                     1.0   13                 0.000620
           1.0       0.0       3.0   2.0   0                  0.000620
           0.0       1.0       1.0   2.0   13                 0.000620
                               2.0   3.0   9                  0.000620
                               1.0   2.0   9                  0.000620
                                           8                  0.000620
           1.0       0.0       3.0   5.0   10                 0.000620
           0.0       1.0       1.0   2.0   7                  0.000620
                               2.0   5.0   12                 0.000620
                               1.0   2.0   6                  0.000620
                               2.0   4.0   13                 0.000620
                               1.0   2.0   2                  0.000620
                               3.0   5.0   1                  0.000620
                               2.0   4.0   14                 0.000620
                               4.0   1.0   10                 0.000620
                               5.0   1.0   1                  0.000620
           1.0       0.0       1.0   2.0   4                  0.000620
           0.0       1.0       2.0   4.0   4                  0.000620
                               1.0   2.0   3                  0.000620
                                           5                  0.000620
                               2.0   2.0   3                  0.000620
           1.0       0.0       3.0   3.0   4                  0.000620
                               4.0   5.0   12                 0.000620
           0.0       1.0       1.0   3.0   11                 0.000620
                               4.0   4.0   7                  0.000620
                                     1.0   11                 0.000620
                               2.0   5.0   4                  0.000620
                               5.0   2.0   3                  0.000620
                               3.0   1.0   0                  0.000620
                               5.0   2.0   5                  0.000620
           1.0       0.0       3.0   3.0   11                 0.000620
           0.0       1.0       1.0   5.0   12                 0.000620
                               4.0   5.0   0                  0.000620
                                           1                  0.000620
           1.0       0.0       5.0   5.0   11                 0.000620
           0.0       1.0       3.0   1.0   4                  0.000620
           1.0       0.0       5.0   5.0   12                 0.000620
           0.0       1.0       4.0   5.0   10                 0.000620
                                           14                 0.000620
                               3.0   1.0   7                  0.000620
           1.0       0.0       3.0   2.0   14                 0.000620
                               4.0   4.0   1                  0.000620
           0.0       1.0       1.0   3.0   12                 0.000620
                                     4.0   12                 0.000620
           1.0       0.0       5.0   4.0   12                 0.000620
           0.0       1.0       5.0   5.0   4                  0.000620
1.0        0.0       0.0       5.0   2.0   10                 0.000620
0.0        0.0       1.0       2.0   2.0   14                 0.000620
                               3.0   2.0   8                  0.000620
                               1.0   3.0   13                 0.000620
           1.0       0.0       3.0   4.0   12                 0.000620
           0.0       1.0       1.0   4.0   11                 0.000620
                                     3.0   14                 0.000620
                               4.0   4.0   4                  0.000620
                               2.0   2.0   13                 0.000620
                               3.0   1.0   3                  0.000620
                                           12                 0.000620
           1.0       0.0       4.0   5.0   1                  0.000620
Name: count, dtype: float64